当用户在我的设置视图中单击按钮时,我想在状态栏中更新 NSStausItem 的 button.title 属性。但是,NSStatusItem 当前没有改变。
应用委托:
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.variableLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
statusItem.button?.title = "A title"
}
func updateTitle(newTitle : String) {
statusItem.button?.title = newTitle
}
设置视图控制器:
@IBAction func didKlickChange(_ sender: Any) {
AppDelegate().updateTitle(newTitle: "Updated title")
}
当我运行应用程序时,StatusBar 会显示一个标题为“A title”的新 StatusItem。太好了,到目前为止。但是当我点击按钮时,唯一发生的事情是一个新的状态项在旧状态项旁边出现了很短的时间。旧的没有更新。有没有合适的解决方案?
谢谢你的帮助!