Search code examples
swiftxcodestoryboardviewcontrolleridentifier

'Storyboard doesn't contain a view controller with identifier 'TimeController'' error in Swift


I am trying to send an Int from one view controller to another in swift, but I am getting this error. There is another post on this same topic, but the advice given is to 'clean' the project which does not work for me. Here is my code:

First view controller:

import UIKit

class UserInput: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    var myInt = Int()

    override func viewDidLoad() {
    super.viewDidLoad()

        myInt = 5

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func submit(_ sender: Any) {

        let myVC = storyboard?.instantiateViewController(withIdentifier: "TimeController") as! TimeController
        myVC.intPassed = myInt
        navigationController?.pushViewController(myVC, animated: true)
    }
}

Second view controller:

import Foundation
import UIKit

class TimeController: UIViewController {

    var intPassed = Int()

    override func viewDidLoad() {
        super.viewDidLoad()

        print(intPassed)

        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Solution

  • Ensure you have inserted TimeController as the Storyboard ID in your storyboard.

    enter image description here