1

我随机从一些 iOS 10.3.3 用户那里得到这个堆栈跟踪:

-[_TtGCs26_SwiftDeferredNSDictionarySSP__ length]: unrecognized selector sent to instance 0x174421880

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x183416fe0 __exceptionPreprocess
1  libobjc.A.dylib                0x181e78538 objc_exception_throw
2  CoreFoundation                 0x18341def4 __methodDescriptionForSelector
3  CoreFoundation                 0x18341af54 ___forwarding___
4  CoreFoundation                 0x183316d4c _CF_forwarding_prep_0
5  UIKit                          0x189a437d0 -[UIButton _updateTitleView]
6  UIKit                          0x1895bf828 -[UIButton tintColorDidChange]
7  UIKit                          0x189a5d9d8 -[_UITintColorVisitor _visitView:]
8  UIKit                          0x189a5e0bc _UIViewVisitorEntertainVisitors
9  UIKit                          0x189a5d1f0 _UIViewVisitorRecursivelyEntertainDescendingVisitors
10 UIKit                          0x189a5d2a0 _UIViewVisitorRecursivelyEntertainDescendingVisitors
11 UIKit                          0x189a5cb3c _UIViewVisitorEntertainDescendingTrackingVisitors
12 UIKit                          0x1895445a8 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke
13 Foundation                     0x183e51abc -[NSISEngine withBehaviors:performModifications:]
14 UIKit                          0x1895443b0 -[UIView(Hierarchy) _postMovedFromSuperview:]
15 UIKit                          0x1895502ac -[UIView(Internal) _addSubview:positioned:relativeTo:]
16 UIKit                          0x18954fbc8 -[UIView(Hierarchy) addSubview:]
17 UIKit                          0x18982d81c -[UIView _setTraitStorageSubviews:]
18 Foundation                     0x183e2c68c -[NSObject(NSKeyValueCoding) setValue:forKey:]
19 UIKit                          0x189846b78 -[UIView(CALayerDelegate) setValue:forKey:]
20 UIKit                          0x1899ccb50 -[_UIRelationshipTraitStorage applyRecordsMatchingTraitCollection:]
21 UIKit                          0x1899cb500 -[NSObject(_UITraitStorageAccessors) _applyTraitStorageRecordsForTraitCollection:]
22 UIKit                          0x189831364 -[UIView _traitCollectionDidChangeFromOldCollection:toNewCollection:scaleDidChange:]
23 UIKit                          0x189831488 -[UIView _wrappedProcessDidChangeRecursivelyFromOldTraits:toCurrentTraits:scaleDidChange:forceNotification:]
24 UIKit                          0x189ea84c8 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:]
25 UIKit                          0x1898316ec -[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:]
26 UIKit                          0x189545c50 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
27 QuartzCore                     0x186736274 -[CALayer layoutSublayers]
28 QuartzCore                     0x18672ade8 CA::Layer::layout_if_needed(CA::Transaction*)
29 QuartzCore                     0x18672aca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
30 QuartzCore                     0x1866a634c CA::Context::commit_transaction(CA::Transaction*)
31 QuartzCore                     0x1866cd3ac CA::Transaction::commit()
32 QuartzCore                     0x1866cde78 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
33 CoreFoundation                 0x1833c49a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
34 CoreFoundation                 0x1833c2630 __CFRunLoopDoObservers
35 CoreFoundation                 0x1833c2a7c __CFRunLoopRun
36 CoreFoundation                 0x1832f2da4 CFRunLoopRunSpecific
37 GraphicsServices               0x184d5d074 GSEventRunModal
38 UIKit                          0x1895adc9c UIApplicationMain
39 <myapp>                          0x10006bf9c main (main.m:14)
40 libdyld.dylib                  0x18230159c start

对于某些用户 -[UIButton _intrinsicSizeWithinSize:] 替换为 -[UIButton _updateTitleView]

该应用程序同时使用 Objective-C 和 Swift 3。

我无法在我的设备/模拟器上重现崩溃。

不幸的是,我没有关于这个问题的任何其他信息。

有人遇到过类似的问题吗?

TIA

4

1 回答 1

0

终于找到问题的根源了!

通过以下代码可以获得崩溃

NSArray *array = @[
    @{@"key": @1, @"name": @"Name1"},
    @{@"key": @2, @"name": @"Name2"},
    @{@"key": @3, @"name": @"Name3"}
];
NSString *title = array[1];
[button setTitle: title forState: UIControlStateNormal];

我正在分配NSDictionary @{@"key": @2, @"name": @"Name2"}to title(没有警告),然后我将NSDictionaryas a传递NSString[UIButton setTitle:forState:]方法。

我修复了重新定义array为的问题

NSArray<NSDictionary<NSString *, id> *> *array;

并将我分配给的值title从更改array[1]array[1][@"name"]

于 2017-08-23T08:54:37.173 回答