本文介绍了NSMenuItem未启用迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的项目中有一个NSMenuItem:
I have a NSMenuItem in my project:
var statusBar = NSStatusBar.systemStatusBar()
var statusItem : NSStatusItem = NSStatusItem()
var menuItem : NSMenuItem = NSMenuItem()
var mainMenu = NSMenu()
override func viewDidLoad() {
super.viewDidLoad()
menuItem.title = "Holidays"
menuItem.action = Selector("setWindowVisible:")
menuItem.target = nil
menuItem.keyEquivalent = "M"
menuItem.enabled = true
mainMenu.addItem(menuItem)
statusItem = statusBar.statusItemWithLength(-1)
statusItem.menu = mainMenu
statusItem.title = statusItem.menu?.itemAtIndex(0)?.title
}
它将项目添加到菜单,但未启用:
It adds the item to menu, but it isn't enabled:
http://i68.fastpic.ru/big/2015/0116/39/8e444aa8fb6f113bcdad2753e915b439.jpeg
选择器也有效,函数setWindowVisible
属于同一类:
And the selector is valid too, the function setWindowVisible
exists in the same class:
func setWindowVisible(sender : AnyObject?) {
self.window!.orderFront(self)
}
推荐答案
目标必须是self
而不是nil.
The target needs to be self
instead of nil.
menuItem.target = self
这篇关于NSMenuItem未启用迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!