当用户从UITableCell
a 中选择UITableViewController
时,显示segue 会向UINavigationController
执行
import UIKit
class ItemNavigationController: UINavigationController {
// this is our "model" - its value is set by the "prepareForSegue" method of the parent UITableViewController
var item: String?
override func viewDidLoad() {
super.viewDidLoad()
// here I want to "forward" the "model" to the ItemViewController
// self.someMethodToGetItemViewController.item = item
}
}
在ItemViewController
上设置模型后,我们“刷新”标签:
import UIKit
class ItemViewController: UIViewController {
var item: String!
@IBOutlet
weak var nameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// does not do anything because item is empty...
nameLabel.text = item
}
}
如何设置item
ItemViewController
的{{1}}属性?
答案 0 :(得分:1)
如果ItemViewController是ItemNavigationController的topViewController
,那么你可以通过调用topViewController方法直接获取它,否则,你应该循环遍历ItemNavigationController的viewControllers
属性并找到它。