skip to Main Content

The error log like below

2021-06-03 09:59:16.251029+0800 testing2[7167:2095191] [Storyboard] Unknown class _TtC8testing218NextViewController in Interface Builder file. Could not cast value of type 'UIViewController' (0x1d8c46428) to 'NextViewController' (0x102a90c50). 2021-06-03 09:59:16.252513+0800 testing2[7167:2095191] Could not cast value of type 'UIViewController' (0x1d8c46428) to 'NextViewController' (0x102a90c50). (lldb)

There is a link for my demo detail
https://drive.google.com/file/d/1LcY3hb3yGYf_3bZpo6qnvZPMviVp2Jft/view?usp=sharing

I am a noob, please detail to say the step~ Thank you

2

Answers


  1. Solution 1

    You can’t use pushViewController without navigationController.
    If you want you code will work, you need add navigationController to you ViewController.
    Click to your ViewController -> in upper menu select Editor -> choose Embed In -> Navigation Controller.

    enter image description here

    Solution 2

    Add Show segue to your NextViewController.
    enter image description here

    Then rename to nextSegue and change kind to Present Modally and set presentation to Full Screen.

    enter image description here

    In your ViewController:

    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
        }
    
        @IBAction func btn_next(_ sender: UIButton) {
            performSegue(withIdentifier: "nextSegue", sender: nil)
        }
        
    
    }
    
    Login or Signup to reply.
  2. Swift class name has module name as prefix, Make sure your ViewController and NextViewController both tick Inherit Module From Target with same module name in storyboard, giving the NextViewController a identifier call next, and you can do the following code.

    @IBAction func btn_next(_ sender: UIButton) {
        
        guard let next = self.storyboard?.instantiateViewController(identifier: "next") as? NextViewController else {
            print("next is uninitialized")
            return
        }
        self.present(next, animated: true, completion: nil)
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search