【发布时间】:2023-03-09 20:26:02
【问题描述】:
我正在尝试将 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.
}
}
【问题讨论】:
-
你在storyboard中给TimeController的标识符了吗?
-
你试过关闭xcode再打开吗?有时它适用于情节提要中的错误
标签: swift xcode storyboard viewcontroller identifier