1
我有一個綁定到實例內部變量的標籤。 當我更改變量時,可以打印出新內容,但標籤保留原始內容。更改Swift類中的綁定變量
class myClass: NSObject {
var text : String = "Initial"
override init() {
text = "Init"
}
func change() {
text = "Changed"
}
}
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var instance = myClass()
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
instance.change()
print(instance.text)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
print(instance.text)給我「改變」,但標籤保持「Init」。
爲什麼綁定在這種情況下不起作用?
該標籤具有「綁定到應用控制器」「self.instance.text」結合
由於
你爲什麼從AppDelegate中調用它? – Laffen
我需要稍後與AppDelegate中的對象進行通信。從ViewController調用顯示相同的問題 –
您是否正在編輯UIViewController中的變量? – Laffen