SIGABRT NSCFNumber长度

时间:2014-02-16 20:17:28

标签: ios crash unrecognized-selector

我在堆栈跟踪中遇到NSCFNumber和UILabel drawTextInRect:无法识别的选择器错误。这就是堆栈跟踪的样子:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xad5a260'
*** First throw call stack:
(
    0   CoreFoundation                      0x01f039e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c838e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01fa0a43 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01ef3d0b ___forwarding___ + 1019
    4   CoreFoundation                      0x01ef38ee _CF_forwarding_prep_0 + 14
    5   UIKit                               0x00b02773 -[UILabel _shadow] + 45
    6   UIKit                               0x00b03bd2 -[UILabel drawTextInRect:] + 70
    7   UIKit                               0x00b0610c -[UILabel drawRect:] + 98
    8   UIKit                               0x009b4893 -[UIView(CALayerDelegate) drawLayer:inContext:] + 504
    9   QuartzCore                          0x0060db39 -[CALayer drawInContext:] + 123
    10  QuartzCore                          0x0060da6a _ZL16backing_callbackP9CGContextPv + 96
    11  QuartzCore                          0x004fbf3c CABackingStoreUpdate_ + 2656
    12  QuartzCore                          0x0060da02 ___ZN2CA5Layer8display_Ev_block_invoke + 93
    13  QuartzCore                          0x00641ee3 x_blame_allocations + 15
    14  QuartzCore                          0x0060d86d _ZN2CA5Layer8display_Ev + 1519
    15  QuartzCore                          0x0060dab9 -[CALayer _display] + 33
    16  QuartzCore                          0x0060d276 _ZN2CA5Layer7displayEv + 144
    17  QuartzCore                          0x0060da93 -[CALayer display] + 33
    18  QuartzCore                          0x00601c43 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 323
    19  QuartzCore                          0x00601cbc _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
    20  QuartzCore                          0x005683ee _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    21  QuartzCore                          0x00569779 _ZN2CA11Transaction6commitEv + 393
    22  QuartzCore                          0x00569e4c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    23  CoreFoundation                      0x01ecbb6e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    24  CoreFoundation                      0x01ecbabf __CFRunLoopDoObservers + 399
    25  CoreFoundation                      0x01ea9a54 __CFRunLoopRun + 1076
    26  CoreFoundation                      0x01ea91d3 CFRunLoopRunSpecific + 467
    27  CoreFoundation                      0x01ea8feb CFRunLoopRunInMode + 123
    28  GraphicsServices                    0x03d1c5ee GSEventRunModal + 192
    29  GraphicsServices                    0x03d1c42b GSEventRun + 104
    30  UIKit                               0x009463db UIApplicationMain + 1225
    31  PocketCTF                           0x00026e8d main + 141
    32  libdyld.dylib                       0x02881725 start + 0
)

我不确定哪条线导致此错误,因为Xcode只是断点到主运行循环。我已经尝试使用异常和符号断点来查看导致问题的行但没有用。我有什么办法可以找到造成这种情况的线路吗?

1 个答案:

答案 0 :(得分:2)

经过几个小时的调试,当然我在这里发帖后找到解决方案..我试图根据NSDictionary值设置文本,如此,

[label setText:[json objectForKey:@"text"]];

但UILabel不是id,而是NSString(正如@danielbeard所指出的那样)

[label setText:[[json objectForKey:@"text"] stringValue]];