UIStoryboard无法找到带标识符的视图控制器
我有一个ios应用程序使用故事板和一堆视图控制器。
添加新的ViewController后,配置了标识(Storyboard ID)
我尝试使用以下代码实例化新的ViewController:
SurveyNewViewController *newSurvey = [[self storyboard] instantiateViewControllerWithIdentifier:@"newSurveyView"]; [self presentViewController:newSurvey animated:YES completion:nil];
一切似乎都是正确的,但在模拟器上运行应用程序时崩溃:
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'newSurveyView''
这有什么可能的解释吗? 我在系统的不同位置使用了相同的方法,效果很好。
在运行项目后,尝试从iPhone模拟器中删除您的应用程序,清理项目并构建。
试试看:
[[UIStoryboard storyboardWithName:@"StoryboardNameOfnewSurveyView" bundle:nil] instantiateViewControllerWithIdentifier:@"newSurveyView"];
如果它有效,我认为[自我故事板]不会给你正确的对象;)。
设置Storyboard ID
因为它在Xcode 8.0中使用,并选中Use Storyboard ID
选项。 还要检查在Storyboard
中为该ViewController
设置的类字段。