简体   繁体   中英

returned nil from -traitCollection, which is not allowed in Xcode 11 Beta

Assertion failure in UITraitCollection * _Nonnull returned nil from -traitCollection, which is not allowed? when I try to run Xcode 11 beta in ios 13 it crashed. I don't know what was wrong.

[super init]

I ran across this problem because one of the unnamed previous coders on my codebase, whom I frequently curse, didn't call [super init] on a class that implements the UITraitEnvironment (aka UIView or UIViewController )!

If I could wield a battle hammer backwards five years in time, I would.

This implementation in a subclass of UIViewController

- (id)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
    _startPosition = startPosition;
    _scrollViewHeight = scrollViewHeight;

    self.isPdfView = YES;

    return self;
}

was updated to…

- (instancetype)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
    self = [super initWithNibName:nil bundle:nil];
    _startPosition = startPosition;
    _scrollViewHeight = scrollViewHeight;
    _isPdfView = YES;
    return self;
}

and resolved the crash I started receiving in Xcode 11 / iOS 13.

This is how iOS 13 and Xcode 11 deal with the main thread checker inconsistencies.

basically, you are updating the UI from a background thread. Just make sure you're updating all your UI in the main thread.

Simply wrap the code that updates your UI inside DispatchQueue.main.async { } .

Just simple put your code in main thread of UI update :

DispatchQueue.main.async
             {
          // Put your code here 
           }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM