[英]How to change NSStatusItem out of class
I create a NSStatusItem in a class named StatusMenuController like this 我像这样在名为StatusMenuController的类中创建一个NSStatusItem
class StatusMenuController: NSObject {
let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
override func awakeFromNib() {
let icon = NSImage(named: "MenuBar")
icon?.isTemplate = true // best for dark mode
if let button = statusItem.button {
button.image = icon
button.action = #selector(StatusMenuController.showPomoNow)
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
button.target = self
}
statusItem.title = "25:00"
}
I can change the title easily in this class. 我可以在这堂课中轻松更改标题。 It will change like I expected.
它会像我预期的那样发生变化。
I reference this class in AppDelegate 我在AppDelegate中引用了此类
let statusMenu = StatusMenuController()
Add change it in other class 在其他课程中添加更改
statusMenu.statusItem.title = "24:31"
I expect the text 25:00 will change to "24:31",but it looks like this. 我希望文本25:00将更改为“ 24:31”,但是看起来像这样。 screenshot
截图
System create another NSStatusItem. 系统创建另一个NSStatusItem。 How can I change the one which created in StatusMenuController.
如何更改在StatusMenuController中创建的那个。
OOPer's comment is right. OOPer的评论是正确的。 I found a object which create another StatusMenuController from Storyboard.
我找到了一个从Storyboard创建另一个StatusMenuController的对象。 I delete the object,Then everything is OK.
我删除对象,然后一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.