故事板实例化 WithIdentifier 导致 iOS 13 崩溃

Storyboard instantiateWithIdentifier cause crash on iOS 13

Xcode 11(测试版) 中测试我的应用程序以获得 iOS-13(测试版) 更新当我试图从情节提要中实例化 viewController 时,我遇到了崩溃。

在以前的版本中,使用以下代码可以正常工作:

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

现在 iOS 13 Apple 推出了新方法,即

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

在 iOS-13 中执行这两种方法会导致崩溃。虽然崩溃显示在其他地方。

这是我的崩溃报告。

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

注意:临时解决方案

我也遇到了这个问题,我找到了两个临时修复方法。首先是创建 object/property 需要实例化的控制器,并在您的控制器 viewDidLoad 中创建 instantiateViewControllerWithIdentifier。应用程序不会崩溃。

其次是在dispatch_async(dispatch_get_main_queue())中实例化controller。这两个技巧都对我有用。