【发布时间】:2016-07-21 19:37:39
【问题描述】:
我使用这个函数来创建一个NSMenuitems。它们都被标记为 2。
func addToComputerInfoMenu (title: String)
{
let addToComputerItem : NSMenuItem = NSMenuItem(title: "\(title)" , action: #selector(openWindow), keyEquivalent: "")
addToComputerItem.attributedTitle = NSAttributedString(string: "\(title)", attributes: [NSFontAttributeName: NSFont.systemFontOfSize(14), NSForegroundColorAttributeName: NSColor.blackColor()])
addToComputerItem.tag = 2
addToComputerItem.enabled = true
computerInfoMenu.addItem(addToComputerItem)
}
我想以编程方式删除所有带有“2”标签的项目。我尝试使用 .itemWithTag 和 .indexOfItemWithTag。我似乎无法遍历列表。
let itemswithindex2 = computerInfoMenu.itemWithTag(2)
【问题讨论】:
标签: swift nsmenu nsmenuitem