故事板崩溃OSX

时间:2016-09-07 06:19:28

标签: objective-c macos cocoa storyboard

我看到这种崩溃是随机发生的:

Fatal Exception: NSInvalidArgumentException
    *** setObjectForKey: object cannot be nil (key: NSViewController-Qmf-WE-Bmb)
0  CoreFoundation                 0x7fff95e504da __exceptionPreprocess
1  libobjc.A.dylib                0x7fff923eef7e objc_exception_throw
2  CoreFoundation                 0x7fff95d4a414 -[__NSDictionaryM setObject:forKey:]
3  AppKit                         0x7fff9857f917 -[NSStoryboard nibForControllerWithIdentifier:]
4  AppKit                         0x7fff9857fc11 -[NSStoryboard instantiateControllerWithIdentifier:]
5  AppKit                         0x7fff982e733b -[NSStoryboardSegueTemplate _perform:]
6  AppKit                         0x7fff983345d7 -[NSViewController performSegueWithIdentifier:sender:]
7  libdispatch.dylib              0x7fff8e5cc93d _dispatch_call_block_and_release
8  libdispatch.dylib              0x7fff8e5c140b _dispatch_client_callout
9  libdispatch.dylib              0x7fff8e5d4c1c _dispatch_main_queue_callback_4CF
10 CoreFoundation                 0x7fff95e059e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
11 CoreFoundation                 0x7fff95dc48dd __CFRunLoopRun
12 CoreFoundation                 0x7fff95dc3ed8 CFRunLoopRunSpecific
13 HIToolbox                      0x7fff99b4b935 RunCurrentEventLoopInMode
14 HIToolbox                      0x7fff99b4b76f ReceiveNextEventCommon
15 HIToolbox                      0x7fff99b4b5af _BlockUntilNextEventMatchingListInModeWithFilter
16 AppKit                         0x7fff97e3bdf6 _DPSNextEvent
17 AppKit                         0x7fff97e3b226 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
18 AppKit                         0x7fff97e2fd80 -[NSApplication run]
19 AppKit                         0x7fff97df9368 NSApplicationMain
20 libdyld.dylib                  0x7fff8c6875ad start

我已经验证了segue标识符是正确的,故事板是否存在并包含segue。我还验证了一个ID为Qmf-WE-Bmb的视图控制器。

为什么会发生这种情况的任何线索?这是否意味着源VC已解除分配或无法加载目标VC?

1 个答案:

答案 0 :(得分:0)

如果有人遇到同样的问题,我通过在我的基本控制器上用自定义函数替换performSegueWithIdentifier:来规避崩溃:

- (void)performManualSegueWithControllerID:(NSString *)identifier {
    if ([NSThread isMainThread]) {
        NSViewController *controller = [self.storyboard instantiateControllerWithIdentifier:identifier];
        if (controller) {
            MyCustomAnimator *animator = [[MyCustomAnimator alloc] init];
            [animator setAnimateVertically:NO];
            [self prepareForManualSegueToController:controller];
            [self presentViewController:controller animator:animator];
        } else {
            // Some Error
        }
    } else {
        [self performSelectorOnMainThread:@selector(performManualSegueWithControllerID:)
                               withObject:identifier
                            waitUntilDone:NO];
    }
}

- (void)prepareForManualSegueToController:(NSViewController *)controller {

}