'故事板在Swift

时间:2018-06-06 15:54:27

标签: swift xcode storyboard viewcontroller identifier

我试图在一个视图控制器中将一个Int发送到另一个视图控制器,但是我收到了这个错误。关于同一主题还有另一篇文章,但给出的建议是“清理”对我不起作用的项目。这是我的代码:

第一个视图控制器:

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)
    }
}

第二个视图控制器:

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.
    }
}

1 个答案:

答案 0 :(得分:1)

确保您已在故事板中插入了TimeController作为故事板ID。

enter image description here