【问题标题】:reloadRowsAtIndexPaths crashing; reloadData workingreloadRowsAtIndexPaths 崩溃;重新加载数据工作
【发布时间】:2017-09-07 07:19:40
【问题描述】:

当我尝试重新加载如下几行时,我的应用程序崩溃了:

[tblView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];

但是,当我将行替换为时,代码可以正常工作:

[tblView reloadData];

我得到的崩溃是

libc++abi.dylib:以 NSException 类型的未捕获异常终止

【问题讨论】:

  • 表中是否有足够的行要重新加载?
  • 我想你会给我们提供比这更多的信息.​​.....这些行的上下文是什么?例如,rowsToReload 可能指向不在表中的行,从而导致类似于 index out of range 异常。
  • 尝试将rowsToReload 作为数组传递。
  • reloadData 将重新加载整个表。 ReloadRowsAtIndexPath 只会重新加载给定的 indexPath,我猜您的数据似乎有一些变化没有正确反映在您的数据源中?也许改变部分?你的帖子信息不多,所以我只是猜测
  • 你能播下完整的崩溃日志吗?

标签: ios objective-c xcode


【解决方案1】:
UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

[CATransaction begin];
[CATransaction setAnimationDuration:0.3];

[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction 
functionWithControlPoints:0 :1.8 :0 :1]];

[self.menuCollectionView performBatchUpdates:^{
  [tblView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
} completion:^(BOOL finished) {
}];

[CATransaction commit];
[UIView commitAnimations];

【讨论】:

    【解决方案2】:

    用作

     NSIndexPath* indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
    
     NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil];
    
     [tblView  reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
    

    【讨论】:

      【解决方案3】:

      如下所示传递您的 indexPath。

      NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
      [tblView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-07
        • 2016-03-09
        相关资源
        最近更新 更多