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

后端 未结 3 1180
北恋
北恋 2020-12-04 02:10

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 kn

相关标签:
3条回答
  • 2020-12-04 02:30

    [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.

    0 讨论(0)
  • 2020-12-04 02:31

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

    DispatchQueue.main.async
                 {
              // Put your code here 
               }
    
    0 讨论(0)
  • 2020-12-04 02:34

    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 { }.

    0 讨论(0)
提交回复
热议问题