IOS UILable.text填入非字符串时引发的错误

今天因为UILable.text时填入非字符串引发的错误,让我查了一天的时间才总算是装其查出来。

-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000013'
1.错误查了这么久原因1,我在设置UI Text时使用了(NSString *)param这种方式的强转。因为Objective C是可以把数字类型的对象直接传为NSString的,而且它还不会报错。

2.错误查了这么久原因2,虽然我对设置UI Text时catch了Exception,查总是没有办法捕获到相应的异常,不知道IOS在对UILable的值的设置时是不是使用了另外的线程。这个线程的stack如下

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101e5b495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000101ad699e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101eec65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000101e4cd8d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000101e4c938 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001008047c5 -[UILabel _shadow] + 34
    6   UIKit                               0x00000001008059fd -[UILabel drawTextInRect:] + 81
    7   UIKit                               0x0000000100807ab2 -[UILabel drawRect:] + 100
    8   UIKit                               0x00000001006e34bd -[UIView(CALayerDelegate) drawLayer:inContext:] + 474
    9   QuartzCore                          0x00000001002df368 -[CALayer drawInContext:] + 116
    10  QuartzCore                          0x00000001001e3843 CABackingStoreUpdate_ + 2641
    11  QuartzCore                          0x00000001002df274 ___ZN2CA5Layer8display_Ev_block_invoke + 59
    12  QuartzCore                          0x00000001002df113 _ZN2CA5Layer8display_Ev + 1461
    13  QuartzCore                          0x00000001002d4173 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 319
    14  QuartzCore                          0x00000001002d41f5 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
    15  QuartzCore                          0x0000000100247fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
    16  QuartzCore                          0x0000000100249030 _ZN2CA11Transaction6commitEv + 394
    17  QuartzCore                          0x000000010024969d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    18  CoreFoundation                      0x0000000101e26dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    19  CoreFoundation                      0x0000000101e26d37 __CFRunLoopDoObservers + 391
    20  CoreFoundation                      0x0000000101e06522 __CFRunLoopRun + 946
    21  CoreFoundation                      0x0000000101e05d83 CFRunLoopRunSpecific + 467
    22  GraphicsServices                    0x00000001036d6f04 GSEventRunModal + 161
    23  UIKit                               0x0000000100683e33 UIApplicationMain + 1010
    24  hr_ios                              0x00000001000223a3 main + 115
    25  libdyld.dylib                       0x00000001033585fd start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)

根本无法通过这个stack来判断在哪一部分的代码出现问题

你可能感兴趣的:(text)