繁体   English   中英

segue错误:“ NSInvalidArgumentException”,原因:“ Receiver没有带有标识符的segue

[英]Error with segue: 'NSInvalidArgumentException', reason: 'Receiver has no segue with identifier

我的应用出现此错误: 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 {

}

我正在尝试在2nd ViewController访问dateTimeString ,但是每当我单击应该发送的按钮时,我的应用都会因该错误而终止。 这是我第一次尝试使用segue,但是我做得并不好。 解决此错误后,我将能够在2nd ViewController调用dateTimeString并获取在第1st ViewController设置的值?

谢谢!

编辑:我已经在情节提要中完成了标识符。

在情节提要中,您需要为segue设置标识符:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM