Search code examples
uiviewcontrollerstoryboardxcode11ios13

Storyboard instantiateWithIdentifier cause crash on iOS 13


Testing my app in Xcode 11 (beta) for iOS-13 (beta) updates and I'm getting crash on when I tried to instantiate viewController from storyboard.

In previous versions its working fine with the following code:

XYZController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];

Now for iOS 13 Apple introduces new method i.e.

XYZController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER" creator:^__Kindof UIViewController *__Nullable(NSCoder *_Nonnull coder){
    return [XYZController alloc] initWithCoder:coder];
}];

Executing both method in iOS-13 cause crash. While crash shows somewhere else.

Here is my crash report.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '' returned nil from -traitCollection, which is not allowed.


Solution

  • Note: Temporary Solution

    I also have face this issue and there are two temporary fixes I have found. First is to create object/property of the controller that need to be instantiate and instantiateViewControllerWithIdentifier in your controllers's viewDidLoad. App will not crash.

    Second is to instantiate controller in dispatch_async(dispatch_get_main_queue()). These both tricks worked for me.