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

Posted

技术标签:

【中文标题】segue 出错:\'NSInvalidArgumentException\',原因:\'接收者没有带有标识符的 segue【英文标题】:Error with segue: 'NSInvalidArgumentException', reason: 'Receiver has no segue with identifiersegue 出错:'NSInvalidArgumentException',原因:'接收者没有带有标识符的 segue 【发布时间】:2015-09-29 21:20:23 【问题描述】:

我的应用程序出现此错误: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 中设置的值吗?

谢谢!

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

在代码中我注意到你正在调用 [self performSegueWithIdentifier:@"dateTimeStringSegue" sender: nil];而错误是关于'dateTimeString' segue。您确定您的代码与情节提要同步吗? 在第一个视图控制器的prepareForSeque中,NSLog中[segue identifier]的值是什么?

以上是关于segue 出错:'NSInvalidArgumentException',原因:'接收者没有带有标识符的 segue的主要内容,如果未能解决你的问题,请参考以下文章

执行 segue 时出错:-[UITextField 长度]:无法识别的选择器发送到实例 [关闭]

将 unwind segue 与 UISearchController 一起使用时出错

在uiimageview中加载像gif这样的图像时出错

FBRequestConnection startForMeWithCompletionHandler - NSInvalidArgumentException

Segues 和 Segues 不工作的条件

使用多个 Segue |如何使用 Cell 数据来执行特定的 Segue