[英]Application crashes on iOS 13 because of returned nil from -traitCollection, which is not allowed
[英]returned nil from -traitCollection, which is not allowed in Xcode 11 Beta
UITraitCollection 中的斷言失敗 * _Nonnull 從 -traitCollection 返回 nil,這是不允許的? 當我嘗試在 ios 13 中運行 Xcode 11 beta 時它崩潰了。 我不知道出了什么問題。
我遇到了這個問題,因為我的代碼庫中一個未命名的以前的編碼器,我經常詛咒,沒有在實現UITraitEnvironment
(又名UIView
或UIViewController
)的類上調用[super init]
!
如果我能在五年內向后揮舞戰錘,我會的。
這個實現在UIViewController
的子類中……
- (id)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
_startPosition = startPosition;
_scrollViewHeight = scrollViewHeight;
self.isPdfView = YES;
return self;
}
已更新為…
- (instancetype)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
self = [super initWithNibName:nil bundle:nil];
_startPosition = startPosition;
_scrollViewHeight = scrollViewHeight;
_isPdfView = YES;
return self;
}
並解決了我在 Xcode 11 / iOS 13 中開始收到的崩潰。
這就是 iOS 13 和 Xcode 11 處理主線程檢查器不一致的方式。
基本上,您是從后台線程更新 UI。 只需確保您在主線程中更新所有 UI。
只需將更新 UI 的代碼包裝在DispatchQueue.main.async { }
。
只是簡單地將您的代碼放在 UI 更新的主線程中:
DispatchQueue.main.async
{
// Put your code here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.