9
votes

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.

3
Do you have more than 1 storyboard? - rdelmar
Also, what do you do in your [self storyboard] method? - micantox
yes @rdelmar, I have more than one storyboard. @micantox [self storyboard] is a property from UIViewController. - gabrielrios
Is SurveyNewViewController in the same storyboard as the controller you have this code in? - rdelmar
@rdelmar yes, same storyboard. - gabrielrios

3 Answers

38
votes

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

4
votes

Try with that :

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

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

2
votes

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