ios - 在具有容器 View 的 VC 中,prepareForSegue 在 ViewDidload 之前被调用

标签 ios swift segue

我在它的导航 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   
    }
}

Picture

最佳答案

尝试不在 viewDidLoad 中初始化这些变量,而是在 prepareForSegue 方法中。

关于ios - 在具有容器 View 的 VC 中,prepareForSegue 在 ViewDidload 之前被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46225274/

相关文章:

ios - 错误 - 无法使用类型为 'LineChartData' 的参数列表调用类型为 '(xVals: [String], dataSet: LineChartDataSet)' 的初始值设定项

swift - TableViewController问题: won't save user input from textView

ios - 通过 segue 在 View Controller 之间传递数据

swift - 将 "correct"数据从 UITableViewController 中选定的单元格传递到 ViewController

ios - 如何从 iMessage 扩展程序打开托管应用程序?

ios - 无法使用类型为 'Set<String>' 的索引下标类型为 'Int' 的值

c# - 如何通过单击 Xamarin 4 中的 TableView 单元格打开 TableView

ios - 带有 UIAlertAction swift 的增量标签栏角标(Badge)?

ios - 如果我在页面完成之前退出页面,如何取消 URLSession.shared.dataTask?

ios - 我怎样才能让这个过程向相反的方向发展呢?