ios - 回到屏幕时,导致我的应用崩溃的原因是什么?

标签 ios objective-c xcode uitableview nsmutablearray

我在使用自定义类的UITableView中列出了视频。这是标签栏应用程序。当我向下滚动到第8个视频并转到下一个屏幕时,当我返回到视频列表屏幕时,该应用程序将崩溃。我尝试调试,但无法找出问题。这是我从调试器得到的。

2016-06-08 12:47:46.919 Votocast[2283:453809] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 8 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000108ba9d85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010a7f9deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000108a87804 -[__NSArrayM objectAtIndex:] + 212
    3   Votocast                            0x0000000107dfd4de -[HomeView tableView:cellForRowAtIndexPath:] + 958
    4   UIKit                               0x000000010b6914f4 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
    5   UIKit                               0x000000010b69162c -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    6   UIKit                               0x000000010b665c8a -[UITableView _updateVisibleCellsNow:isRecursive:] + 2799
    7   UIKit                               0x000000010b69a686 -[UITableView _performWithCachedTraitCollection:] + 92
    8   UIKit                               0x000000010b681344 -[UITableView layoutSubviews] + 224
    9   UIKit                               0x000000010b5ee980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
    10  QuartzCore                          0x0000000109ff1c00 -[CALayer layoutSublayers] + 146
    11  QuartzCore                          0x0000000109fe608e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    12  QuartzCore                          0x0000000109fe5f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    13  QuartzCore                          0x0000000109fda3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    14  QuartzCore                          0x000000010a008086 _ZN2CA11Transaction6commitEv + 486
    15  UIKit                               0x000000010b52e72e _UIApplicationHandleEventQueue + 7135
    16  CoreFoundation                      0x0000000108acf301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x0000000108ac522c __CFRunLoopDoSources0 + 556
    18  CoreFoundation                      0x0000000108ac46e3 __CFRunLoopRun + 867
    19  CoreFoundation                      0x0000000108ac40f8 CFRunLoopRunSpecific + 488
    20  GraphicsServices                    0x000000010d4ebad2 GSEventRunModal + 161
    21  UIKit                               0x000000010b533f09 UIApplicationMain + 171
    22  Votocast                            0x0000000107e48d8f main + 111
    23  libdyld.dylib                       0x000000010cc0792d start + 1
    24  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

在viewWillAppear中,我从该数组中删除了所有对象,并调用了webservice。但是,在我从Web服务获得响应之前,应用程序崩溃到cellForRowAtIndexPath中的一行。您的一点帮助将不胜感激。

编辑:

我注意到该应用程序仅在我的tableview减速时崩溃,然后转到下一个屏幕并返回到视频列表屏幕。我尚未完成有关减速的任何类型的代码。

最佳答案

您可以使用viewWillAppear方法从Array中清除所有对象,但是此后您是否要重新加载tableview。

因为这可能导致崩溃。您删除了所有对象,但tableview尝试转到最后一个滚动索引。因此会导致崩溃。

希望这会帮助你。

关于ios - 回到屏幕时,导致我的应用崩溃的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37696059/

相关文章:

ios - 如何在 iOS 中缩放 ScrollView 图像?

ios - NSSortDescriptor与Comparator使用实际对象而不是键值

iOS 11 : SSL error occurred and connection to server cannot be made

iphone - 如何在另一个 View Controller 中调用 NSNotificationCenter 函数?

ios - 自定义类型Core Data属性问题

android - 无法从 Objective C 解密 AES 加密字符串

ios - Error Domain = NSURLErrorDomain代码= -1005“网络连接丢失。” -在iOS 9中通过https发生

iphone - 摆脱可恶的状态栏并不像在 iOS 7 上看起来那么容易

ios - 为什么我们没有 UIBarMetricsLandscapePad?

ios - Swift 2.2 内存管理