iOS - 将文本设置为UILabel属性的异常

时间:2014-04-16 04:54:52

标签: ios ios7 uilabel abcustomuinavcontroller

我在View Controllers之一中遇到一个奇怪的问题,每件事情都很好并且加载得很好,但 when ever i set a Value to the View i get an Exception related to layer 。但是,我没有在 Interface Builder 或代码中为图层设置任何属性。下面是我收到的日志,现在对我来说毫无意义

-[__NSCFNumber length]: unrecognized selector sent to instance 0x923a4e0
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x923a4e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x01ef31e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01bf08e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01f90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01ee350b ___forwarding___ + 1019
    4   CoreFoundation                      0x01ee30ee _CF_forwarding_prep_0 + 14
    5   UIKit                               0x00a6d463 -[UILabel _shadow] + 45
    6   UIKit                               0x00a6e8c2 -[UILabel drawTextInRect:] + 70
    7   UIKit                               0x00a70dfc -[UILabel drawRect:] + 98
    8   UIKit                               0x0091f453 -[UIView(CALayerDelegate) drawLayer:inContext:] + 504
    9   QuartzCore                          0x00213f39 -[CALayer drawInContext:] + 123
    10  QuartzCore                          0x00213e6a _ZL16backing_callbackP9CGContextPv + 96
    11  QuartzCore                          0x001024fc CABackingStoreUpdate_ + 2656
    12  QuartzCore                          0x00213e02 ___ZN2CA5Layer8display_Ev_block_invoke + 93
    13  QuartzCore                          0x002482d7 x_blame_allocations + 15
    14  QuartzCore                          0x00213c6d _ZN2CA5Layer8display_Ev + 1519
    15  QuartzCore                          0x00213eb9 -[CALayer _display] + 33
    16  QuartzCore                          0x00213676 _ZN2CA5Layer7displayEv + 144
    17  QuartzCore                          0x00213e93 -[CALayer display] + 33
    18  QuartzCore                          0x00210fb7 -[CALayer displayIfNeeded] + 57
    19  QuartzCore                          0x002113b1 -[CALayer renderInContext:] + 192
    20  QuartzCore                          0x00213376 -[CALayer _renderSublayersInContext:] + 413
    21  QuartzCore                          0x002118bc -[CALayer renderInContext:] + 1483
    22  QuartzCore                          0x00213376 -[CALayer _renderSublayersInContext:] + 413
    23  QuartzCore                          0x002118bc -[CALayer renderInContext:] + 1483
    24  QuartzCore                          0x00213376 -[CALayer _renderSublayersInContext:] + 413
    25  QuartzCore                          0x002118bc -[CALayer renderInContext:] + 1483
    26  SilverStar                          0x00011fad -[UIView(ABExtras) imageInNavController:] + 525
    27  SilverStar                          0x00013005 -[CubeNavigationController pushViewController:animated:] + 549
    28  SilverStar                          0x0000c936 -[MSArticleViewController detailsbuttonTapped:] + 438
    29  libobjc.A.dylib                     0x01c02880 -[NSObject performSelector:withObject:withObject:] + 77
    30  UIKit                               0x008b23b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    31  UIKit                               0x008b2345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    32  UIKit                               0x009b3bd1 -[UIControl sendAction:to:forEvent:] + 66
    33  UIKit                               0x009b3fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    34  UIKit                               0x009b3243 -[UIControl touchesEnded:withEvent:] + 641
    35  UIKit                               0x00c482e3 _UIGestureRecognizerUpdate + 7166
    36  UIKit                               0x008f1a5a -[UIWindow _sendGesturesForEvent:] + 1291
    37  UIKit                               0x008f2971 -[UIWindow sendEvent:] + 1021
    38  UIKit                               0x008c45f2 -[UIApplication sendEvent:] + 242
    39  UIKit                               0x008ae353 _UIApplicationHandleEventQueue + 11455
    40  CoreFoundation                      0x01e7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    41  CoreFoundation                      0x01e7c10b __CFRunLoopDoSources0 + 235
    42  CoreFoundation                      0x01e991ae __CFRunLoopRun + 910
    43  CoreFoundation                      0x01e989d3 CFRunLoopRunSpecific + 467
    44  CoreFoundation                      0x01e987eb CFRunLoopRunInMode + 123
    45  GraphicsServices                    0x036c25ee GSEventRunModal + 192
    46  GraphicsServices                    0x036c242b GSEventRun + 104
    47  UIKit                               0x008b0f9b UIApplicationMain + 1225

注意:我不确定您可能需要哪个代码部分。所以,让我知道我会在这里添加问题

1 个答案:

答案 0 :(得分:1)

您正在传递NSNumber而不是NSString。试试这个:

NSString *myString = [aNumber stringValue]; // aNumber is a NSNumber
self.label.text = myString

希望这会有所帮助.. :)