我有3个NSToolbarItems第一个工作得很好,另外两个,每次我选择它们都会抛出
[16392:513506] -[NSToolbarItem isEqualToString:]: unrecognized selector sent to instance 0x6080001203c0
2015-05-26 19:59:26.871 MyApp[16392:513506] (
0 CoreFoundation 0x00007fff89f9703c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8a40176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff89f9a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff89edfe24 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff89edf998 _CF_forwarding_prep_0 + 120
5 AppKit 0x00007fff9649d74e +[NSToolbar _shouldIgnoreItemIdentifier:] + 35
6 AppKit 0x00007fff9649d6f7 removeIgnoredIdentifiers + 89
7 AppKit 0x00007fff9675e526 -[NSToolbar selectableItemIdentifiers] + 224
8 AppKit 0x00007fff9675e411 -[NSToolbar _isSelectableItemIdentifier:] + 34
9 AppKit 0x00007fff9675e385 -[NSToolbar setSelectedItemIdentifier:] + 79
10 AppKit 0x00007fff96654f3c -[NSToolbarItemViewer mouseDown:] + 4951
11 AppKit 0x00007fff96bc52fc -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125
12 AppKit 0x00007fff96554d76 -[NSWindow sendEvent:] + 470
13 AppKit 0x00007fff96551312 -[NSApplication sendEvent:] + 2504
14 AppKit 0x00007fff9647ac68 -[NSApplication run] + 711
15 AppKit 0x00007fff963f7354 NSApplicationMain + 1832
16 IPLocation 0x000000010001769d main + 109
17 libdyld.dylib 0x00007fff96ffd5c9 start + 1
18 ??? 0x0000000000000003 0x0 + 3
)
我试着从故事板中断开连接并重新连接它们,但没有任何改变。IBAction甚至没有被调用。
我ViewController func toolbarSelectableItemIdentifiers(toolbar: NSToolbar) -> [AnyObject] {
// let array = toolbar.items.filter { contains(Identifier.allValues, $0.itemIdentifier ) }//wrong!
return Identifier.allValues
}
委托只需要标识符的名称,而不需要可选择项本身。