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?
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.
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 .
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:
May be this will help you.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With