Storyboard does not 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 it makes sense to separate the storyboards, so I created a new storyboard file New File -> User Interface -> StoryBoard , cut out all the controllers related to user management (Login , register, password recovery ...) and paste them into a 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 this?

+6
source share
2 answers

You need to create a new storyboard instance and get the LoginViewController StoryboardId window

 //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 "Identity" inspector 

Hope this helps, Happy Coding :)

+4
source

I think your problem is here, go to Main.storyBoard after that click on your viewController, which you want to trigger after that, to give it an identifier here:

enter image description here

Perhaps this will help you.

+15
source

Source: https://habr.com/ru/post/979275/


All Articles