Home > database >  Cannot display View (Programmatically)
Cannot display View (Programmatically)

Time:07-25

I'm learning how to make an app with just a code in Swift. I have encountered this problem:

This is action of a button.

@objc func answerAction() {
        
        let story = UIStoryboard(name: "Main", bundle: nil)
        let controller = story.instantiateViewController(withIdentifier: "AccountViewController") as! AccountViewController
        self.present(controller, animated: true, completion: nil)
        
    }

If I press it, it shows this error:

Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle </Users/mas/Library/Developer/CoreSimulator/Devices/A3BEC6D0-3AA6-4193-A755-1181DD580576/data/Containers/Bundle/Application/C80D5D36-EBD8-44D4-AF14-B64E2E7E5587/AppForTest.app> (loaded)"

As I understand, the problem is that I have deleted Main.storyboard and app cannot reach it. So how I should declare in a answerAction story constant?

CodePudding user response:

@objc func answerAction() {
    
    let controller = AccountViewController()
    self.present(controller, animated: true, completion: nil)  
}
  • Related