【发布时间】:2021-05-26 10:36:22
【问题描述】:
当我们执行 segue 时,很容易获得目标视图控制器,因此我们可以使用 prepare(for:) 方法将数据传递给它。
我想知道按下导航控制器的后退按钮时执行此操作的正确方法。
我已经设法拼凑出一些可行的东西,但是在导航控制器中使用我对视图控制器层次结构的了解而不是动态获取目的地感觉是错误的。可能是我想多了?
override func willMove(toParent parent: UIViewController?) {
super.willMove(toParent: parent)
// This method is called more than once - parent is only nil when back button is pressed
if (parent == nil) {
guard let destination = self.navigationController?.viewControllers.first as? MyTableViewController else {
return
}
print("destination is \(destination)")
// set delegate of my networking class to destination here
// call async method on networking class to retrieve updated data for my table view
}
}
【问题讨论】:
标签: swift uinavigationcontroller