![](/img/trans.png)
[英]-[UIView adjustedContentInset]: unrecognized selector sent to instance in ios 11
[英]iOS 11 and up crashing with -[UIView setDrawsWithVibrantLightMode:]: unrecognized selector sent to instance
我注意到在 iOS 11 及更高版本上出現此消息的應用程序崩潰顯着增加。 這似乎是UIKit
正在調用的內部 API,堆棧跟蹤顯示它在UITableViewCell
內部:
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setDrawsWithVibrantLightMode:]: unrecognized selector sent to instance 0x15defa6d0'
Last Exception Backtrace:
0 CoreFoundation 0x0000000181691d04 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x00000001808e0528 objc_exception_throw + 52
2 CoreFoundation 0x000000018169f1c8 -[NSObject(NSObject) doesNotRecognizeSelector:] + 136
3 UIKit 0x000000018ae8711c -[UIResponder doesNotRecognizeSelector:] + 292
4 CoreFoundation 0x00000001816976b0 ___forwarding___ + 1376
5 CoreFoundation 0x000000018157d01c _CF_forwarding_prep_0 + 88
6 UIKit 0x000000018b022d58 -[UITableViewCell _setSeparatorDrawsInVibrantLightMode:] + 216
7 UIKit 0x000000018abf5ef0 -[UITableViewCell setSeparatorColor:] + 340
8 UIKit 0x000000018abf451c __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1228
9 UIKit 0x000000018aad6e34 +[UIView(Animation) performWithoutAnimation:] + 100
10 UIKit 0x000000018abf3f64 -[UITableView _configureCellForDisplay:forIndexPath:] + 268
11 UIKit 0x000000018ae03a00 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 844
12 UIKit 0x000000018ae03eac -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 76
13 UIKit 0x000000018ade39f0 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2136
14 UIKit 0x000000018ab99508 -[UITableView layoutSubviews] + 136
我一直無法重現這個問題,但它在許多用戶設備上一直崩潰,並且設備或操作系統版本之間沒有共同的線程,除了它只發生在 iOS 11 及更高版本上。
最終發現這是在輔助功能設置下啟用了深色設置時UIKit
的錯誤:
Settings -> General -> Accessibility -> Increase Contrast -> Darken Colors
如果您遇到此崩潰,請嘗試打開/關閉該設置以重現它。
現在我們通過簡單地將此方法實現為擴展中的Void
函數來抑制這一點:
@available(iOS 11.0, *)
extension UITableViewCell {
func _setSeparatorDrawsInVibrantLightMode(_ value: Bool) {
}
}
所以UIKit
可以調用它,但它什么也不做(並且不會使應用程序崩潰)。
正如 jwswart 在他的回答中所說,應該添加下一個代碼:
@available(iOS 11.0, *)
extension UITableViewCell {
@objc func _setSeparatorDrawsInVibrantLightMode(_ value: Bool) {
}
}
但有時您會收到相同的錯誤消息,但針對不同的問題。 要修復它,您還應該添加:
@available(iOS 11.0, *)
extension UITableView {
@objc func _setSeparatorsDrawInVibrantLightModeUIAppearance(_ value: Bool) {
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.