ios - 快速准备 segue 不工作

标签 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
}

图形 View Controller :

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
 }
}

我只是想不通为什么以及如何解决这个问题 任何想法将不胜感激

最佳答案

UIStoryboardSegue 在其destination 属性 中包含您要转换到的实际 View Controller 。您不是将数据传递给该 View Controller ,而是将其传递给您在 prepareForSegue 中创建的全新 View Controller (当您离开该函数时,它会立即被删除)。

您可能想要以下内容:

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

我是在没有编译器的情况下输入的,因此您可能需要对其进行调整。

关于ios - 快速准备 segue 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43816868/

相关文章:

ios - 如何创建带有 DPI 集的 UIImage?

javascript - 使用 Angular 加载部分页面并编译 Controller

model-view-controller - MVC-ARS 是否优于经典 MVC 以防止过载?

ios - $cordova.geolocation 未在 IOS 中获取当前位置的经度和纬度

ios - iOS 应用角标(Badge)中的随机数

iphone - 是否有网站展示如何重新创建特定的 iOS UI 范例?

ios - 创建一个包含 UIAlertView、UIActivityIndi​​cator 等函数的类,并在各种 viewController 中回调它们

ios - 在 Tableview 中,我想知道如何在单元格最后位置设置多行 UILabel

ios - 当 Sprite 被触摸并移出节点(按钮)边界时如何停止 Sprite 的移动

javascript - 使用 agility.js 进行页面布局和组合