在 - [NSScrollView reloadData]中捕获了非致命的NSInvalidArgumentExecption

时间:2017-01-30 11:50:29

标签: swift macos cocoa nscollectionview

我已经在swift中构建了一个基于文档的应用程序,然后我在其旁边添加了一个NSCollectionView添加按钮。该按钮将调用NSOpenPanel,然后所选项目的图标应显示在集合视图中。但是,当我点击NSOpenPanel中的“打开”按钮时,会将以下内容打印到控制台:

2017-01-30 19:36:54.205343 CookRecipes[5004:203650] -[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770
2017-01-30 19:36:54.224746 CookRecipes[5004:203650] -[NSVBSavePanel didEndPanelWithReturnCode:] caught non-fatal NSInvalidArgumentException '-[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770' with backtrace (
    0   CoreFoundation                      0x00007fff9e2010db __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffb2e92a2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff9e281cd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00007fff9e1742a3 ___forwarding___ + 1059
    4   CoreFoundation                      0x00007fff9e173df8 _CF_forwarding_prep_0 + 120
    5   CookRecipes                         0x0000000100004239 _TFFC11CookRecipes8Document7addFileFT_T_U_FSiT_ + 457
    6   CookRecipes                         0x00000001000047ef _TTRXFo_dSi__XFdCb_dSi__ + 47
    7   AppKit                              0x00007fff9c0665e4 -[NSVBSavePanel didEndPanelWithReturnCode:] + 68
    8   AppKit                              0x00007fff9c6ba09d -[NSVBSavePanel completeModeless:] + 74
    9   AppKit                              0x00007fff9befa721 -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] + 597
    10  Foundation                          0x00007fff9fbcb71d NSKeyValueNotifyObserver + 350
    11  Foundation                          0x00007fff9fbcafb4 NSKeyValueDidChange + 486
    12  Foundation                          0x00007fff9fb99e96 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
    13  ViewBridge                          0x00007fffb184c066 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 447
    14  ViewBridge                          0x00007fffb18d052b withHintInProgress + 487
    15  ViewBridge                          0x00007fffb184be83 -[NSViewBridge setObject:forKey:withKVO:] + 1014
    16  ViewBridge                          0x00007fffb184a95a -[NSViewBridge nonLocalChangeInProgress:block:] + 390
    17  ViewBridge                          0x00007fffb18aa260 -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 256
    18  ViewBridge                          0x00007fffb18aa3e8 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
    19  CoreFoundation                      0x00007fff9e1756dc __invoking___ + 140
    20  CoreFoundation                      0x00007fff9e175561 -[NSInvocation invoke] + 289
    21  ViewBridge                          0x00007fffb18d052b withHintInProgress + 487
    22  ViewBridge                          0x00007fffb18d025a __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
    23  ViewBridge                          0x00007fffb1851df2 +[NSViewServiceApplication withHostPID:invoke:] + 46
    24  ViewBridge                          0x00007fffb18d011d __deferNSXPCInvocationOntoMainThread_block_invoke + 179
    25  ViewBridge                          0x00007fffb18cfd0a __deferBlockOntoMainThread_block_invoke_2 + 544
    26  CoreFoundation                      0x00007fff9e19771c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    27  CoreFoundation                      0x00007fff9e1789d4 __CFRunLoopDoBlocks + 356
    28  CoreFoundation                      0x00007fff9e178516 __CFRunLoopRun + 1894
    29  CoreFoundation                      0x00007fff9e177b54 CFRunLoopRunSpecific + 420
    30  HIToolbox                           0x00007fff9d702a5c RunCurrentEventLoopInMode + 240
    31  HIToolbox                           0x00007fff9d702891 ReceiveNextEventCommon + 432
    32  HIToolbox                           0x00007fff9d7026c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    33  AppKit                              0x00007fff9bca85b4 _DPSNextEvent + 1120
    34  AppKit                              0x00007fff9c422d6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
    35  AppKit                              0x00007fff9bc9cf35 -[NSApplication run] + 926
    36  AppKit                              0x00007fff9bc67850 NSApplicationMain + 1237
    37  CookRecipes                         0x000000010000c344 main + 84
    38  libdyld.dylib                       0x00007fffb3774255 start + 1
    39  ???                                 0x0000000000000003 0x0 + 3
)
2017-01-30 19:36:54.239473 CookRecipes[5004:203650] -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] caught non-fatal NSInvalidArgumentException '-[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770' with backtrace (
    0   CoreFoundation                      0x00007fff9e2010db __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffb2e92a2a objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff9e281cd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00007fff9e1742a3 ___forwarding___ + 1059
    4   CoreFoundation                      0x00007fff9e173df8 _CF_forwarding_prep_0 + 120
    5   CookRecipes                         0x0000000100004239 _TFFC11CookRecipes8Document7addFileFT_T_U_FSiT_ + 457
    6   CookRecipes                         0x00000001000047ef _TTRXFo_dSi__XFdCb_dSi__ + 47
    7   AppKit                              0x00007fff9c0665e4 -[NSVBSavePanel didEndPanelWithReturnCode:] + 68
    8   AppKit                              0x00007fff9c6ba09d -[NSVBSavePanel completeModeless:] + 74
    9   AppKit                              0x00007fff9befa721 -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] + 597
    10  Foundation                          0x00007fff9fbcb71d NSKeyValueNotifyObserver + 350
    11  Foundation                          0x00007fff9fbcafb4 NSKeyValueDidChange + 486
    12  Foundation                          0x00007fff9fb99e96 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
    13  ViewBridge                          0x00007fffb184c066 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 447
    14  ViewBridge                          0x00007fffb18d052b withHintInProgress + 487
    15  ViewBridge                          0x00007fffb184be83 -[NSViewBridge setObject:forKey:withKVO:] + 1014
    16  ViewBridge                          0x00007fffb184a95a -[NSViewBridge nonLocalChangeInProgress:block:] + 390
    17  ViewBridge                          0x00007fffb18aa260 -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 256
    18  ViewBridge                          0x00007fffb18aa3e8 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
    19  CoreFoundation                      0x00007fff9e1756dc __invoking___ + 140
    20  CoreFoundation                      0x00007fff9e175561 -[NSInvocation invoke] + 289
    21  ViewBridge                          0x00007fffb18d052b withHintInProgress + 487
    22  ViewBridge                          0x00007fffb18d025a __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
    23  ViewBridge                          0x00007fffb1851df2 +[NSViewServiceApplication withHostPID:invoke:] + 46
    24  ViewBridge                          0x00007fffb18d011d __deferNSXPCInvocationOntoMainThread_block_invoke + 179
    25  ViewBridge                          0x00007fffb18cfd0a __deferBlockOntoMainThread_block_invoke_2 + 544
    26  CoreFoundation                      0x00007fff9e19771c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    27  CoreFoundation                      0x00007fff9e1789d4 __CFRunLoopDoBlocks + 356
    28  CoreFoundation                      0x00007fff9e178516 __CFRunLoopRun + 1894
    29  CoreFoundation                      0x00007fff9e177b54 CFRunLoopRunSpecific + 420
    30  HIToolbox                           0x00007fff9d702a5c RunCurrentEventLoopInMode + 240
    31  HIToolbox                           0x00007fff9d702891 ReceiveNextEventCommon + 432
    32  HIToolbox                           0x00007fff9d7026c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
    33  AppKit                              0x00007fff9bca85b4 _DPSNextEvent + 1120
    34  AppKit                              0x00007fff9c422d6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
    35  AppKit                              0x00007fff9bc9cf35 -[NSApplication run] + 926
    36  AppKit                              0x00007fff9bc67850 NSApplicationMain + 1237
    37  CookRecipes                         0x000000010000c344 main + 84
    38  libdyld.dylib                       0x00007fffb3774255 start + 1
    39  ???                                 0x0000000000000003 0x0 + 3
)

我认为问题所在的代码应该在此段中:

extension Document : AddAttachmentDelegate {
    internal func addFile() {
        let panel = NSOpenPanel()

        panel.allowsMultipleSelection = false
        panel.canChooseDirectories = false
        panel.canChooseFiles = true

        panel.begin { (result) -> Void in
            if result == NSModalResponseOK, let resultURL = panel.urls.first {
                do {
                    try self.addAttachmentAtURL(url: resultURL)
                    self.attachmentsList?.reloadData()
                } catch let error as NSError {
                    if let window = self.windowForSheet {
                        NSApp.presentError(error, modalFor: window, delegate: nil, didPresent: nil, contextInfo: nil)
                    } else {
                        NSApp.presentError(error)
                    }
                }
            }
        }
    }
}

我不知道发生了什么事。希望你能帮忙。

编辑:attachmentsList通过以下方式连接:

@IBOutlet weak var attachmentsList: NSCollectionView!

0 个答案:

没有答案