快速准备segue不工作

时间:2017-05-06 04:55:33

标签: ios swift model-view-controller segue

CalViewController:

let brain =CalculatorBrain()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let graph = GraphController()
    graph.brain.record = brain.record
}

GraphViewController:

var brain = CalculatorBrain() {
    didSet {
        draw.variables = ["M": 1]
        let value = brain.evaluate(using: draw.variables)
        print(value)
//at that time outlet didn't set it prints the value work just fine
    }
}

@IBOutlet weak var graphView: GraphView! {
    didSet {
        draw.variables = ["M": 1]
        let value = brain.evaluate(using: draw.variables)
        print(value)
//when outlet got set it not working it print nothing
 }
}

我无法弄清楚为什么以及如何解决这个问题 任何想法都会欣赏

1 个答案:

答案 0 :(得分:1)

UIStoryboardSegue包含您要在其destination property中转换到的实际视图控制器。您将数据传递给在prepareForSegue中创建的全新视图控制器(当您离开该函数时会立即删除该控制器),而不是将数据传递给该视图控制器。

您可能需要以下内容:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let graph = segue.destination as? GraphController {
        graph.brain.record = brain.record
    }
}

我输入了没有编译器的好处,所以你可能需要调整它。