我在它的导航 Controller 中有一个 View Controller 和一个 UISearchBar
。我添加了一个容器 View ,其中包含 2 个 ViewController。
我需要将一个变量传递给我的容器 View 和容器 View 的 View Controller 。但是我不能这样做,因为 prepareForSegue 发生在我的主要 VC 的 viewDidLoad()
之前。
我需要将这些变量传递给我的容器 View ,但在初始化这些变量之前会调用 prepareForSegue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("prepare for segue FirstViewController")
if segue.identifier == "mapViewContainer" {
let vc = segue.destination as! MasterMapViewController
vc.segmentControl = self.container
vc.resultsViewController = self.resultsViewController
vc.searchController = self.searchController
}
}
最佳答案
尝试不在 viewDidLoad
中初始化这些变量,而是在 prepareForSegue
方法中。
关于ios - 在具有容器 View 的 VC 中,prepareForSegue 在 ViewDidload 之前被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46225274/