我试图在一个视图控制器中将一个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.
}
}