标识符存在时,接收器没有与之对应的segue

3

For an iOS app, I have a story board and multiple controllers, and a segue going from controller GameClass to controller SettingsClass. The segue, in view Controller GameClass has an identifier called GameToSettings:

enter image description here

However, when I want to call the segue from my GameClass:

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

I get the error message

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<GameClass: 0xcf0c550>) has no segue with identifier 'GameToSettings''

I tried many tips I found in other articles (like renaming the storyboard, cleaning the project, changing simulator format, giving another name to the segue, ), but the issue keeps coming.

I've uploaded a version of my code here: http://www.petits-suisses.ch/Issue.zip. Any suggestion of what I could continue trying ?
Thanks.


将你的项目上传到某个地方,然后在这里发布链接,我会查看它。 - duci9y
设置控制器是否嵌入导航控制器? - hackerinheels
流程如下:导航控制器 -> 菜单控制器 --(presentViewController)-> 游戏控制器 --(performSegueWithIdentifier)-> 设置控制器。 - Laurent Crivello
Duci9y:我已将代码上传到http://www.petits-suisses.ch/Issue.zip。点击红点,然后点击蓝点。错误将随之出现。感谢您的建议! - Laurent Crivello
1个回答

8
您不应该以这种方式实例化视图控制器:
GameClass *myNewVC = [[GameClass alloc] init];

相反,使用

 [[UIStoryboard storyboardWithName:@"storyboard name" bundle:nil] instantiateViewControllerWithIdentifier:@"vc identifier">]

编辑: 请查看https://github.com/mac-cain13/R.swift

它将允许您使用自动完成、类型安全的方法轻松实例化: R.storyboard.main.myViewController


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接