UIStoryboard Couldn't find view controller with identifier

南楼画角 提交于 2019-11-29 19:14:10

问题


I have an ios application using storyboards with a bunch of view controllers.

After Adding a new ViewController, and configured the identify (Storyboard ID)

I try to instantiate the new ViewController with the following code:

SurveyNewViewController *newSurvey = [[self storyboard] instantiateViewControllerWithIdentifier:@"newSurveyView"];
[self presentViewController:newSurvey animated:YES completion:nil];

Everything seems to be right, but when running the application on the simulator it crashes:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:   
'Storyboard (<UIStoryboard: 0xa340fa0>) doesn't contain a view controller 
with identifier 'newSurveyView''

Is there any possible explanation for this? I have used this same approach in different places on the system and it works well.


回答1:


Try remove your app from iPhone Simulator, clean project and build, after run your project.




回答2:


Try with that :

[[UIStoryboard storyboardWithName:@"StoryboardNameOfnewSurveyView" bundle:nil] instantiateViewControllerWithIdentifier:@"newSurveyView"];

If it works, I think [self storyboard] don't give you the right object ;).




回答3:


Set Storyboard ID as this is use in Xcode 8.0 and check the Use Storyboard ID option. Also check the Class field is set in Storyboard to that ViewController.



来源:https://stackoverflow.com/questions/19007882/uistoryboard-couldnt-find-view-controller-with-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!