Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard doesn't contain a view controller with identifier ... when using multiple storyboard files

I used to have all my view controllers in the same storyboard, I decided that makes sense to split up the storyboards so I created a new storyboard file New File -> User Interface -> StoryBoard, cut all the controllers related with the user management (Login, register, password recover ...) and pasted them in the new file

Now when I call storyboard.instantiateViewControllerWithIdentifier("LoginViewController") it crashes with the following error:

'Storyboard (<UIStoryboard: 0x...>) doesn't contain a view 
            controller with identifier 'LoginViewController''

How can I solve that?

like image 317
Addev Avatar asked Dec 08 '14 11:12

Addev


People also ask

How do I set the identifier for ViewController in storyboard?

Step 1: Set a Storyboard IDIn 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.

How do I embed a view controller in navigation controller storyboard?

Storyboard setup In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


2 Answers

I think your problem is here, navigate to the Main.storyBoard after that click on your viewController which you want to initiate after that give it to the identifier here:

enter image description here

May be this will help you.

like image 162
Dharmesh Kheni Avatar answered Oct 07 '22 02:10

Dharmesh Kheni


You have to create the new storyboard instance, and get the LoginViewController StoryboardId

//Here, create an instance of the second storyboard excluding the extension(.storyboard), 
var storyBoard = UIStoryboard(name: "SecondStoryBoard", bundle: nil) 

//Here instantiate view controller with the storyboard instance, 
//Before that create a storyboardId for the corresponding view controller.
var loginVC = storyBoard.instantiateViewControllerWithIdentifier("loginViewController") as LoginViewController

//Here, the storyboard identifier is "loginViewController" which is created in the respective view controller's "Identity" inspector

Hope this helps, Happy Coding :)

like image 39
Suresh Kumar Durairaj Avatar answered Oct 07 '22 04:10

Suresh Kumar Durairaj