【问题标题】:ReloadSections crash : iOS 9ReloadSections 崩溃:iOS 9
【发布时间】:2016-01-28 08:46:21
【问题描述】:

我有一个带有可展开/可折叠部分的表格视图。它在 iOS 8 中运行良好,但在 iOS 9 中的 reloadSections 时崩溃。这是代码:

NSRange range = NSMakeRange(selectedSection, 1); [_tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:range] withRowAnimation:UITableViewRowAnimationAutomatic];

我已经查看了这个问题,似乎有些人遇到了它,但没有一个解决方案对我有用。当然我可以重新加载表格,但这不会给我动画的外观,我只是不希望整个表格视图重新加载。这是我唯一的日志(通过控制台上的 bt 命令):

thread #1: tid = 0xfecd, 0x25be16aa UIKit__46-[UITableView _updateWithItems:updateSupport:]_block_invoke + 98, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffc)

frame #0: 0x25be16aa UIKit__46-[UITableView _updateWithItems:updateSupport:]_block_invoke + 98
frame #1: 0x25d074fc UIKit__46-[UITableView _updateWithItems:updateSupport:]_block_invoke1011 + 184
frame #2: 0x25be10b4 UIKit-[UITableView _updateWithItems:updateSupport:] + 2348
frame #3: 0x25bc5684 UIKit-[UITableView _endCellAnimationsWithContext:] + 10648
frame #4: 0x25bc2b5a UIKit-[UITableView _updateSections:updateAction:withRowAnimation:headerFooterOnly:] + 434
frame #5: 0x25bc299e UIKit`-[UITableView reloadSections:withRowAnimation:] + 38
frame #6: 0x0028d956 MyAPP-[MyView expandCollapseSection:](self=0x16f90170, _cmd=0x0096e193, sender=0x16fec2d0) + 1230 at MyView.m:256
frame #7: 0x25a09770 UIKit-[UIApplication sendAction:to:from:forEvent:] + 80
frame #8: 0x25a09700 UIKit-[UIControl sendAction:to:forEvent:] + 64
frame #9: 0x259f161e UIKit-[UIControl _sendActionsForEvents:withEvent:] + 446
frame #10: 0x25a09050 UIKit-[UIControl touchesEnded:withEvent:] + 616
frame #11: 0x259c2fc6 UIKit_UIGestureRecognizerUpdate + 10934
frame #12: 0x25a01e10 UIKit-[UIWindow _sendGesturesForEvent:] + 904
frame #13: 0x25a015c2 UIKit-[UIWindow sendEvent:] + 622
frame #14: 0x259d2118 UIKit-[UIApplication sendEvent:] + 204
frame #15: 0x259d0756 UIKit_UIApplicationHandleEventQueue + 5134
frame #16: 0x217fd256 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
frame #17: 0x217fce46 CoreFoundation__CFRunLoopDoSources0 + 454
frame #18: 0x217fb1ae CoreFoundation__CFRunLoopRun + 806
frame #19: 0x2174dbb8 CoreFoundationCFRunLoopRunSpecific + 516
frame #20: 0x2174d9ac CoreFoundationCFRunLoopRunInMode + 108
frame #21: 0x229c7af8 GraphicsServicesGSEventRunModal + 160
frame #22: 0x25a39fb4 UIKitUIApplicationMain + 144
frame #23: 0x0009a1ec MyAppmain(argc=1, argv=0x0108bb24) + 108 at main.m:17

我曾尝试使用更新块 (beginUpdates) 和动画块,但徒劳无功。 任何帮助表示赞赏。

【问题讨论】:

    标签: ios objective-c uitableview ios9


    【解决方案1】:

    我遇到了同样的问题,但仅限于 iPhone 6 并且仅在某些部分。它适用于 iPhone6 plus。每个设备都使用 .reloadData() 但我想要一个漂亮的动画。当我将折叠部分的行数设置为 1 而不是 0 时,它也可以工作。该问题与在 iOS9 中重新加载空白部分有关。 我使用了这项工作,因此它至少是表格视图的动画更新。这里是 Swift 代码:

    UIView.transitionWithView(self.yourTableView,
                              duration: 0.35,
                              options: .TransitionCrossDissolve,
                              animations:
        { () -> Void in
            self.forecastTableView.reloadData()
        },
                              completion: nil); 
    

    【讨论】:

      【解决方案2】:

      尝试在 [self.tableview beginUpdates][self.tableview endUpdates] 中封装您的 section reload 语句:

      [self.tableview beginUpdates] 
      NSRange range   = NSMakeRange(indexPath.section, 1);
      NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
      [self.tableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
      [self.tableview endUpdates]
      

      希望对你有帮助:)

      【讨论】:

      • 我试过这个没有任何成功。对不起,我应该在上面提到它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 2016-01-03
      • 2015-09-01
      • 2015-12-29
      • 2015-10-08
      • 2015-12-16
      • 2018-12-12
      相关资源
      最近更新 更多