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