Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 772
Syed Qamar Abbas Avatar asked Aug 02 '19 10:08

Syed Qamar Abbas


1 Answers

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.

like image 118
M Zubair Shamshad Avatar answered Nov 05 '22 17:11

M Zubair Shamshad