重新加载表后行数更改时应用程序崩溃

时间:2014-11-14 06:41:41

标签: ios uitableview

在我的iOS应用程序中,有一个带有tableview的视图。表格单元格是从远程服务器上的PHP文件加载的。我还在视图控制器上放了一个应该重新加载数据的NSTimer。

单元格包含可能在时间间隔内更改的信息。只有当细胞数量在一段时间间隔内没有变化时,这才能正常工作。如果按时间间隔添加单元格,则应用程序崩溃。

这是NSTimer的代码:

self.timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(refrescar) userInfo:nil repeats:YES];

这是方法refrescar的代码:

- (void)refrescar {

    total_actual =0;
    total =0;
    [self viewDidLoad];


}

我也试过这个:

 - (void)refrescar {

        total_actual =0;
        total =0;
        [self.tableView reloadData];


    }

但该应用程序与其他代码[self viewDidLoad];

一样崩溃

欢迎任何帮助。

错误日志:

2014-11-13 23:52:23.299 RestAppXXI[1552:607] -[NSNull length]: unrecognized selector sent to instance 0xcb6068
2014-11-13 23:52:23.429 RestAppXXI[1552:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0xcb6068'
*** First throw call stack:
(
    0   CoreFoundation                      0x00b6a1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x031588e5 objc_exception_throw + 44
    2   CoreFoundation                      0x00c07243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x00b5a50b ___forwarding___ + 1019
    4   CoreFoundation                      0x00b5a0ee _CF_forwarding_prep_0 + 14
    5   UIKit                               0x01fd2cc7 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 57
    6   UIKit                               0x01fd2b13 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 85
    7   UIKit                               0x01fd662e -[UILabel _intrinsicSizeWithinSize:] + 173
    8   UIKit                               0x01fd6751 -[UILabel intrinsicContentSize] + 91
    9   UIKit                               0x024b07ef -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 36
    10  UIKit                               0x024b0480 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 511
    11  UIKit                               0x024b67bf -[UIView(AdditionalLayoutSupport) updateConstraints] + 110
    12  UIKit                               0x01fd6579 -[UILabel updateConstraints] + 189
    13  UIKit                               0x024b6058 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 239
    14  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    15  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    16  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    17  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    18  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    19  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    20  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    21  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    22  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    23  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    24  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    25  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    26  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    27  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    28  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    29  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    30  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    31  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    32  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    33  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    34  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    35  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    36  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    37  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    38  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    39  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    40  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    41  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    42  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    43  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    44  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    45  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    46  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    47  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    48  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    49  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    50  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    51  UIKit                               0x024b6157 __UIViewRecursionHelper + 40
    52  CoreFoundation                      0x00b0bc69 CFArrayApplyFunction + 57
    53  UIKit                               0x024b5ffc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
    54  UIKit                               0x024b61d6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
    55  UIKit                               0x024aa878 __62-[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 43
    56  Foundation                          0x02f0b68c -[NSISEngine withBehaviors:performModifications:] + 107
    57  Foundation                          0x02d9b3c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
    58  UIKit                               0x024aa590 -[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 225
    59  UIKit                               0x024aa467 -[UIWindow(UIConstraintBasedLayout) layoutSublayersOfLayer:] + 90
    60  libobjc.A.dylib                     0x0316a82b -[NSObject performSelector:withObject:] + 70
    61  QuartzCore                          0x0171a45a -[CALayer layoutSublayers] + 148
    62  QuartzCore                          0x0170e244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    63  QuartzCore                          0x0170e0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    64  QuartzCore                          0x016747fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    65  QuartzCore                          0x01675b85 _ZN2CA11Transaction6commitEv + 393
    66  QuartzCore                          0x01676258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    67  CoreFoundation                      0x00b3236e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    68  CoreFoundation                      0x00b322bf __CFRunLoopDoObservers + 399
    69  CoreFoundation                      0x00b10254 __CFRunLoopRun + 1076
    70  CoreFoundation                      0x00b0f9d3 CFRunLoopRunSpecific + 467
    71  CoreFoundation                      0x00b0f7eb CFRunLoopRunInMode + 123
    72  GraphicsServices                    0x041945ee GSEventRunModal + 192
    73  GraphicsServices                    0x0419442b GSEventRun + 104
    74  UIKit                               0x01e18f9b UIApplicationMain + 1225
    75  RestAppXXI                          0x000305ed main + 141
    76  libdyld.dylib                       0x049eb6d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

2 个答案:

答案 0 :(得分:0)

这与您的UITableView无关。这很可能来自您尝试访问的字符串,但它是nil

答案 1 :(得分:-1)

用户异常断点要调试,你在NSNull对象上调用长度方法

为什么要使用NSTimer,您可以在从服务器获取响应后重新加载表