UIStoryboard Couldn't find view controller with identifier
Asked Answered
H

3

9

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.

Homonym answered 25/9, 2013 at 14:36 Comment(7)
Do you have more than 1 storyboard?Cacilie
Also, what do you do in your [self storyboard] method?Loram
yes @rdelmar, I have more than one storyboard. @Loram [self storyboard] is a property from UIViewController.Homonym
Is SurveyNewViewController in the same storyboard as the controller you have this code in?Cacilie
@Cacilie yes, same storyboard.Homonym
Well, I can't see anything wrong then. Try doing a clean on the project. Maybe close Xcode and reopen.Cacilie
@Cacilie looks like this fixed. Cleaned the project, removed it from the simulador and running made it work.Homonym
C
38

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

Colp answered 25/9, 2013 at 17:5 Comment(3)
remove? ask user to remove too?Exempt
OMG, this one really helps. Thank you for the hint.Elliot
What will happen when existing users get the update?Dementia
V
4

Try with that :

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

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

Vancouver answered 25/9, 2013 at 15:10 Comment(1)
Tried that already and results is the same. Indeed I have other piece of code, like that one, in the same class that works fine.Homonym
S
2

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

Stockade answered 29/9, 2016 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.