嵌入在 NavigationVC 中的视图是否可以直接从 master 设置为 splitVC 轮询的详细信息?

can a view embedded in a NavigationVC set as detail of splitVC poll from the master directly?

我的故事板:

SplitViewController - NavigationController - (Master) CalculatorViewController
     I
NavigationController - (Detail) GraphViewController`

我正在尝试从(细节)设置一个从(主)提取数据的委托 - 但我似乎无法让(Master)将自己设置为委托人:

我在 didLoad(): graphView.calcDataSource = splitViewController?.viewControllers.first as CalculatorViewController 中尝试从 Detail 视图查看,但它因解包 nil 而崩溃 -

如果我尝试在 Master 端的 didLoad() 中设置 graphView.calcDataSource = self,我会得到 "Use of unresolved identifier graphView"

正确的做法是什么?

========

已解决!

(在名为 "Show Graph" 的按钮上有故事板 segue)

//CalculatorViewController.swift:
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject!) {
    if (segue!.identifier == "Show Graph") {
        var yourNextViewController = (segue!.destinationViewController as UINavigationController)
        var detail = yourNextViewController.viewControllers[0] as GraphViewController
        var tempview = detail.view // FORCES THE VIEW object into existence, without this it will compile, but next line will crash at runtime (graphView nil)
        detail.graphView.calcDataSource = self
    }
}

请注意 var tempview = detail.view 在这里很关键,尽管没有被使用。我理解它设置视图和插座..

不看你的代码,我就不知道你的详细视图是如何实例化的。您可以在实例化详细视图的位置设置连接。使用故事板时,这通常在 prepareForSegue 内部完成。