Search code examples
swiftstoryboardviewcontroller

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


fileprivate func showGroupProfile(_ item:HomescreenLongTapItem) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "GroupProfileViewController") as! GroupProfileViewController
    present(vc, animated: true, completion: nil)
}

I need to change VC after press on icon in HomescreenLongTap but I recive that error 'Storyboard () doesn't contain a view controller with identifier 'GroupProfileViewController' I used the StoryboardID in my code. How can I correctly navigate to next ViewController?


Solution

    1. Make sure you set the identifier of the viewcontroller, lets say "GroupProfileViewController"
    2. Make sure this code is NOT in viewDidLoad(). If you have, consider doing this in viewDidAppear()

    Present the code like this example:

    if let storyboard = storyboard{
       let vc = storyboard.instantiateViewController(withIdentifier: "GroupProfileViewController") as! GroupProfileViewController
       self.present(vc, animated: true)
    }