爵士
我正在尝试实现一个表单并传递
下面的Data对象import UIKit
import GRDB
class Staff: Record {
var id: Int64?
var compId: Int64 = 0
var chiName: String = ""
var engName: String = ""
到表视图控制器加载子记录。当涉及到实现时,它似乎变得无效并且没有意义。您能否告诉我如何确保第二视图控制器在这种情况下不接收空对象?
以下是 记录:
第一个UIView控制器
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("view salary X ")
print(dummy)
print(dummy.id ?? "0")
if let secondController = segue.destination as? ViewSalaryTableViewController {
secondController.dummyStaff = dummy
}
}
第二个UITableView控制器:
public var dummyStaff : Staff?
override func viewDidLoad() {
super.viewDidLoad()
..
print("arrive dummyStaff")
print(dummyStaff ?? "njull")
}
故事板部分草稿:
故事板设置
答案 0 :(得分:2)
确保secondController的类型转换正在运行。如果您有多个segue,请使用segue标识符进行区分。下面的代码对我来说很好:
class MyBook {
var name:String!
}
ViewController 1
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Vc1ToVc2" {
let book = MyBook()
book.name = "Harry"
if let destinationVc = segue.destination as? ViewController2 {
destinationVc.book = book
}
}
}
ViewController 2
var book:MyBook?
override func viewDidLoad() {
super.viewDidLoad()
print(book?.name ?? "No name")
}
打印:哈利