Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStoryboard Couldn't find view controller with identifier

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

After Adding a new ViewController, and configured the identify (Storyboard ID) enter image description here

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.

like image 298
gabrielrios Avatar asked Sep 25 '13 14:09

gabrielrios


People also ask

How do I set the identifier for Viewcontroller in storyboard?

Step 1: Set a Storyboard ID In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.

What is UIStoryboard?

A UIStoryboard object manages archived versions of your app's view controllers. At design time, you configure the content of your view controllers visually, and Xcode saves the data needed to recreate that interface in a storyboard file in your app's bundle.

What is Navigation Controller in Xcode?

June 03, 2019. A navigation controller is responsible for managing the navigation of hierarchical content. The navigation controller manages the current displayed screens using the navigation stack. At the bottom of this stack is the root view controller and at the top is the view controller currently displayed.


3 Answers

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

like image 138
Anderson Rodrigues Avatar answered Oct 09 '22 22:10

Anderson Rodrigues


Try with that :

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

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

like image 40
hypo Avatar answered Oct 09 '22 20:10

hypo


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.

Screenshot of dialogue

like image 33
Kunal Avatar answered Oct 09 '22 22:10

Kunal