segue出错:'NSInvalidArgumentException',原因:'Receiver没有带标识符的segue

时间:2015-09-29 21:20:24

标签: ios objective-c uiviewcontroller segue

我的应用程序出现此错误:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ViewController: 0x17e60c10>) has no segue with identifier 'dateTimeString''。代码是这样的:

ViewController.m

 -(IBAction) alarmSetButtonTapped:(id)sender {

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
    [dateFormatter setDateFormat:@"dd:MM:YYYY:ss:mm:hh"];
    NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date ];
    NSLog( @"Alarm Set : %@", dateTimeString );


    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd:MM:YYYY:ss:mm:hh"];
    NSDate *dateTimeSeconds = [[NSDate alloc] init];
    dateTimeSeconds = [dateFormatter1 dateFromString:dateTimeString];
    NSTimeInterval seconds = [[NSDate date] timeIntervalSinceDate:dateTimePicker.date];
    NSLog(@"seconds %.f", seconds);

    NSString *path = [NSString stringWithFormat:@"%@/Alarm-Clock.m4a", [[NSBundle mainBundle] resourcePath]];
    NSURL *soundUrl = [NSURL fileURLWithPath:path];
    _alarmPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
    [_alarmPlayer playAtTime: _alarmPlayer.deviceCurrentTime + seconds];

    NSLog( @"Alarm Set button tapped : %@", dateTimeString );

    [self scheduleLocalNotificationWithDate: dateTimePicker.date];
    [self performSegueWithIdentifier:@"dateTimeStringSegue" sender: nil];
    [self presentMessage:(@"Alarm succesfully set for %@",dateTimeString)];
}

-(IBAction)alarmCancelButtonTapped:(id)sender {
    NSLog( @"Alarm Cancel button tapped");

    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    [self presentMessage:@"Alarm Canceled Lazy Pants!"];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ViewController3 *tvc = segue.destinationViewController;
    NSLog(@"prepareForSegue: %@", segue.identifier);
    if ([[segue identifier] isEqualToString:@"dateTimeStringSegue"])
    {
        tvc.dateTimeString = (@"%@",_dateTimeString);
        NSLog(@"Segue");
    }
}

ViewController.h

@interface ViewController : UIViewController <AVAudioPlayerDelegate>
{
    IBOutlet UIDatePicker *dateTimePicker;
}

@property NSInteger numberOfLoops;
@property(readonly) NSTimeInterval deviceCurrentTime;
@property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
@property (strong, nonatomic) NSString *dateTimeString;


- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;

-(void) presentMessage: (NSString *) message;
-(void) scheduleLocalNotificationWithDate: (NSDate *) fireDate;
-(IBAction) alarmSetButtonTapped:(id)sender;
-(IBAction) alarmCancelButtonTapped:(id)sender;
- (BOOL)playAtTime:(NSTimeInterval)time;

@end

SegueDestination.h

#import "ViewController.h"

@interface ViewController3 : UIViewController

@property(nonatomic, readonly) NSUInteger tapCount;
@property NSInteger numberOfLoops;
@property(readonly) NSTimeInterval deviceCurrentTime;
@property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
@property (strong, nonatomic) NSString *dateTimeString;
@property (strong, nonatomic) IBOutlet UILabel *dateTimePicker;

- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
- (BOOL)playAtTime:(NSTimeInterval)time;

- (IBAction)iconsBtn:(id)sender;


@end

SegueDestination.m

#import "ViewController.h"

@interface ViewController3 ()
{
    AVAudioPlayer *_alarmPlayer;
}
@end

@implementation ViewController3

- (void)viewDidLoad {
    [super viewDidLoad]
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wwv5.jpg"]];


}

- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    if(touch.tapCount == 3) {
        NSLog(@"Twice");
    }
    else
        NSLog(@"UGHHHHH");
}

- (IBAction)iconsBtn:(id)sender {

}

我正在尝试访问dateTimeString中的2nd ViewController,但每当我点击应发送该按钮的按钮时,我的应用就会终止该错误。这是我第一次尝试使用segue而且我用它不太好。如果此错误已排序,我可以在dateTimeString中致电2nd ViewController并获取1st ViewController中设置的值吗?

谢谢!

编辑:我已经在故事板中完成了标识符。

1 个答案:

答案 0 :(得分:0)

在故事板中,您需要为segue设置标识符:

enter image description here