[英]swift prepare segue not working
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
}
}
我只是不知道為什么以及如何解決這個問題,將不勝感激
UIStoryboardSegue
在其destination property
包含要轉換到的實際視圖控制器。 無需將數據傳遞給該視圖控制器,而是將其傳遞給在prepareForSegue
創建的全新視圖控制器(當您離開該函數時,該視圖控制器會立即刪除)。
您可能想要一些類似的東西:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let graph = segue.destination as? GraphController {
graph.brain.record = brain.record
}
}
我輸入的內容沒有編譯器的好處,因此您可能需要對其進行調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.