我在popover中以编程方式构建了一个NSCollectionView,作为OSX的菜单App App的一部分。但是当单击状态项时,numberOfItemsInSection总是被发送到NSButton。我试图调查,但一无所获。代码段如下:
class MyViewController: NSViewController,
NSCollectionViewDataSource,
NSCollectionViewDelegate,
NSCollectionViewDelegateFlowLayout {
override func loadView() {
...
collectionView.collectionViewLayout = NSCollectionViewFlowLayout()
collectionView.dataSource = self
collectionView.delegate = self
...
}
}
// MARK: NSCollectionViewDataSource
func collectionView(collectionView: NSCollectionView,
numberOfItemsInSection section: Int) -> Int {
return 10;
}
func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
}
错误讯息:
2016-04-05 06:13:44.561 [24387:1271747] - [NSButton collectionView:numberOfItemsInSection:]:无法识别的选择器发送到实例0x6000001434f0
2016-04-05 06:13:44.561 [24387:1271747] - [NSButton collectionView:numberOfItemsInSection:]:无法识别的选择器发送到实例0x6000001434f0
2016-04-05 06:13:44.564 [24387:1271747](
0 CoreFoundation 0x00007fff96f764f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff8b5cf73c objc_exception_throw + 48
2 CoreFoundation 0x00007fff96fe01ad - [NSObject(NSObject)doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff96ee6571 转发 + 1009
4 CoreFoundation 0x00007fff96ee60f8 _CF_forwarding_prep_0 + 120
5 UIFoundation 0x00007fff89c05e5b - [NSCollectionViewData _updateItemCounts] + 355
6 UIFoundation 0x00007fff89c06123 - [NSCollectionViewData _prepareToLoadData] + 73
7 UIFoundation 0x00007fff89c067d5 - [NSCollectionViewData validateLayoutInRect:] + 51
8 UIFoundation 0x00007fff89c43adb - [_ NSCollectionViewCore _layoutItems] + 135
9 AppKit 0x00007fff9aca2393 - [NSCollectionView viewWillDraw] + 108
10 AppKit 0x00007fff9a57ba94 - [NSView viewWillDraw] + 1163
11 AppKit 0x00007fff9a57ba94 - [NSView viewWillDraw] + 1163
12 AppKit 0x00007fff9a57b24a - [NSView _sendViewWillDrawInRect:clipRootView:] + 1705
13 AppKit 0x00007fff9a579247 - [NSView displayIfNeeded] + 1260
14 AppKit 0x00007fff9a578d40 - [NSWindow displayIfNeeded] + 232
15 AppKit 0x00007fff9abfd4bb ___NSWindowGetDisplayCycleObserver_block_invoke6365 + 476
16 AppKit 0x00007fff9a5786da __37 + [NSDisplayCycle currentDisplayCycle] _block_invoke + 941
17 QuartzCore 0x00007fff88f70f71 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 85
18 QuartzCore 0x00007fff88f7042c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 160
19 QuartzCore 0x00007fff88f700ec _ZN2CA11Transaction6commitEv + 508
20 QuartzCore 0x00007fff88f7b977 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 71
21 CoreFoundation 0x00007fff96f0b067 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
22 CoreFoundation 0x00007fff96f0afd7 __CFRunLoopDoObservers + 391
23 CoreFoundation 0x00007fff96ee9ef8 CFRunLoopRunSpecific + 328
24 HIToolbox 0x00007fff9c6f1935 RunCurrentEventLoopInMode + 235
25 HIToolbox 0x00007fff9c6f1677 ReceiveNextEventCommon + 184
26 HIToolbox 0x00007fff9c6f15af _BlockUntilNextEventMatchingListInModeWithFilter + 71
27 AppKit 0x00007fff9a420efa _DPSNextEvent + 1067
28 AppKit 0x00007fff9a42032a - [NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
29 AppKit 0x00007fff9a414e84 - [NSApplication run] + 682
30 AppKit 0x00007fff9a3de46c NSApplicationMain + 1176
31 0x0000000100063734 main + 84
32 libdyld.dylib 0x00007fff9b3995ad start + 1
33 ??? 0x0000000000000003 0x0 + 3 )