7
votes

I'm loading a view controller from a story board explicitly and have this code:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:@"InitialScreen"];

But am getting an error "'Storyboard () doesn't contain a view controller with identifier 'InitialScreen'"

Yet as can be seen from the screenshot, the view controller does have that identifier. I've used this identical way of loading controllers before successfully, but no idea why its not working this time. Any ideas what the issue could be?

enter image description here

2

2 Answers

5
votes

I've just found the problem - its an issue with the simulator, I could find absolutely nothing wrong with my code and was 100% sure it was ok, when I've been in that situation in the past I usually find the culprit is Xcode itself. So even though I'd cleaned and rebuilt multiple times I decided to try resetting the contents in the simulator - and bingo it started working. I put it down to a bug in the simulator caching content and not updating to reflect changes made in IB.

0
votes

Does your storyboard name match the name of the storyboard file you're trying to load the view controller from? Usually the storyboards are named something like MainStoryboard_iPhone

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

You should also check to be sure that there are no trailing spaces in the Storyboard ID textfield. Other than that everything else looks like it should work to me.