应用程序崩溃改变uilabel背景颜色

时间:2015-05-14 14:23:42

标签: ios objective-c

我有NSTimer,每2秒调用checkStatus函数:

-(void) checkStatus
{
    @autoreleasepool
    {
        self.lblconnectionStatus.backgroundColor=RGB(0,153,0);
    }
}

该应用程序崩溃:self.lblconnectionStatus.backgroundColor=RGB(0,153,0);

这是错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x02244466 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x01af5a97 objc_exception_throw + 44
    2   CoreFoundation                      0x020fb5a1 -[__NSArrayM insertObject:atIndex:] + 881
    3   CoreFoundation                      0x020fb201 -[__NSArrayM addObject:] + 65
    4   UIKit                               0x00ad559c PushNextClassForSettingIMP + 383
    5   UIKit                               0x00acce56 TaggingAppearanceObjectSetterIMP + 50
    6   GIG-iPad                            0x0017ddcb -[TradeController checkStatus] + 763
    7   Foundation                          0x016f6607 -[NSThread main] + 76
    8   Foundation                          0x016f6560 __NSThread__main__ + 1326
    9   libsystem_pthread.dylib             0x02e20ecf _pthread_body + 138
    10  libsystem_pthread.dylib             0x02e20e45 _pthread_body + 0
    11  libsystem_pthread.dylib             0x02e1ef0e thread_start + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:0)

也许" checkStatus"功能有,

[xxxx addObject:yyy];

问题是yyy是零,试试这个。

if (yyy != nil) {
  [xxxx addObject:yyy];
}