接收器 (<ViewController:>) 没有带有标识符“showAlerting”的segue

Posted

技术标签:

【中文标题】接收器 (<ViewController:>) 没有带有标识符“showAlerting”的segue【英文标题】:Receiver (<ViewController:>) has no segue with identifier 'showAlerting'' 【发布时间】:2015-03-29 00:08:25 【问题描述】:

segue 运行,但应用程序因上述错误而崩溃。为什么我会收到此no segue with identifier 消息?我定义了segue标识符。

这里是 viewDidAppear 方法

- (void)viewDidAppear:(BOOL)animated

   [self performSegueWithIdentifier:@"showAlerting" sender:self];


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

    if ([[segue identifier] isEqualToString:@"showAlerting"])
    
        NSLog(@"Logging showAlerting");
    

我收到了这些日志消息

2015-03-28 20:04:33.025 xxxx[3684:741007] Logging showAlerting
2015-03-28 20:04:33.046 xxxx[3684:741007] xxxxxxxx,,
2015-03-28 20:04:33.111 xxxx[3684:741007]  lat: xxx
2015-03-28 20:04:33.112 xxxx[3684:741007]  lon: xxx
2015-03-28 20:04:33.798 xxxx[3684:741007] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ViewController: 0x17d38930>) has no segue with identifier 'showAlerting''
*** First throw call stack:
(0x2c1a15a7 0x39d87c77 0x2f9830df 0xebde7 0x2f6bb37b 0x2f6bb837 0x2f9701bb 0x2fd00e89 0x2f9726ff 0x2f7b5baf 0x2f7b5a4f 0x2f7b5525 0x2f6d9201 0x2f6d9117 0x2f0d363b 0x276187 0x279e9d 0x2c167891 0x2c165fb1 0x2c0b2b51 0x2c0b2963 0x335f11a9 0x2f704c91 0xea5f5 0x3a330aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

您是否有多个 ViewController 实例? 我不知道,我有一个 Main.storyboardLaunchScreen.xib 是否会生成两个 ViewController 实例? 您要使用的控制器的类是什么?在情节提要中检查其类。 源和目标都是类ViewController 好的,那是你的问题,因为第二个没有附加segue。您应该更改该控制器的类。 【参考方案1】:

问题是情节提要中有同一个类的两个实例;一个有segue,一个没有。被转接的控制器必须是与您转接的控制器不同的类。

【讨论】:

【参考方案2】:

当您尝试访问其 segue 时,您的视图控制器未完全加载。所以调用 super 并完成加载过程,然后调用 prepareForSegue。

  -(void)viewDidAppear:(BOOL)animated
      [super viewDidAppear:animated];
      [self performSegueWithIdentifier:@"showAlerting" sender:self];
    

【讨论】:

我遇到了与[super viewDidAppear:animated]; 相同的错误 我不认为这是问题所在。他应该调用 super,但视图在调用 viewDidAppear 时已完全加载。

以上是关于接收器 (<ViewController:>) 没有带有标识符“showAlerting”的segue的主要内容,如果未能解决你的问题,请参考以下文章

委托创建 ViewController 的新实例

阻止 ViewController 拦截触摸

如何使用NavigationController将数据从UIPickerView传递到以前的ViewController

Vue 如何接受IOS传过来的window数据

Receiver (<ViewController>) 没有带有标识符的 segue

iBeacon 接收器无法识别传输的信号