origds
origds

Reputation: 1037

STORYBOARD EXCEPTION - Storyboard doesn't contain a view controller with identifier

I am currently developing an iOS application for both iPhone and iPad. I'm trying to show a NavigationController to make a module that shows files. In an iPhone it works just fine, but I can´t get it to work in iPad.

I'm getting the following error:

'Storyboard (<UIStoryboard: 0x919b200>) doesn't contain a view controller with identifier 'FilesNavigation''

and this is the code:

case 10: // Files
{
  UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"FilesNavigation"];

  FilesViewController *filesViewController = [storyboard instantiateViewControllerWithIdentifier:@"Files"];

  [navigationController pushViewController:filesViewController animated:YES];

  self.slidingViewController.topViewController = navigationController;

  break;
}

And in my storyboard I have already set the Storyboard ID for the navigation controller.

>##Custom Class 
>Class: UINavigationController
>##Identity
>Storyboard ID: FilesNavigation

I used this code for another case on the switch/case block for other module and it works for iPad too, its the first time that I have this error.

Upvotes: 19

Views: 18740

Answers (5)

Nix Wang
Nix Wang

Reputation: 814

Here's another case:

There are two localized storyboards. Only one of them has the view controller you want.

Upvotes: 9

superarts.org
superarts.org

Reputation: 7238

TL;DR - clear everything and remove old version of the app as well, if there's any.

It may sound crazy, but suppose that if you have changed target name which changed bundle name as well, you might have both the old and new version of the app installed in the simulator / device, and this might cause trouble for the UIStoryboard instance failed to instantiate some view controllers, which might eventually cause the trouble described in the question. To solve it, you need to remove all related apps or simply reset the simulator / device.

Upvotes: 0

origds
origds

Reputation: 1037

I figured it out, the problem was that the Storyboard wasn't updating in the device.

  1. Uninstall the app from the simulator/iPhone/iPad
  2. Product > Clean
  3. Build & Run

As stated in @T0m_Twt's answer in this question

Upvotes: 53

meda
meda

Reputation: 45490

In the right pane, in the identity inspector section give a storyboard Id to your Navigation Controller.

I took a screenshot for you

enter image description here

Upvotes: 11

Justin Holman
Justin Holman

Reputation: 852

By chance, do you have a storyboard for iPhone and a different one for iPad? If you do, then the iPad one might not have a storyboard with that identifier. Also when running on an iPad, set a break point in your code and verify what your "storyboard" object is.

I use a category on UIStoryboard that will give me the storyboards for each platform.

I can use [UIStoryboard storyboardHome] and that will determine if it needs iPad or iPhone specific and return that to me. I also ensure my storyboards follow proper naming. So I would have Home_iPad and Home_iPhone.

Upvotes: 1

Related Questions