0

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?

2
  • Where do you hold your AccountViewController UI layer if you removed storyboard and from the screenshot you attached, it looks like you dont have xib file. If you want to implement it programmatically, you dont need storyboard. Commented Jul 25, 2022 at 9:07
  • If you are not using storyboards remove the let story = ... and replace let controller = ... with let controller = AccountViewController() Commented Jul 25, 2022 at 9:07

1 Answer 1

1
@objc func answerAction() {
    
    let controller = AccountViewController()
    self.present(controller, animated: true, completion: nil)  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.