Swift 中的“故事板不包含标识符为 'TimeController' 的视图控制器”错误
'Storyboard doesn't contain a view controller with identifier 'TimeController'' error in Swift
我试图将 Int 从一个视图控制器发送到 swift 中的另一个视图控制器,但出现此错误。关于同一主题还有另一个 post,但给出的建议是 'clean' 对我不起作用的项目。这是我的代码:
第一个视图控制器:
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.
}
}
确保您已在情节提要中插入 TimeController
作为情节提要 ID。
我试图将 Int 从一个视图控制器发送到 swift 中的另一个视图控制器,但出现此错误。关于同一主题还有另一个 post,但给出的建议是 'clean' 对我不起作用的项目。这是我的代码:
第一个视图控制器:
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.
}
}
确保您已在情节提要中插入 TimeController
作为情节提要 ID。