【问题标题】:Crash while reloading row and the whole table at the same time同时重新加载行和整个表时崩溃
【发布时间】:2011-08-24 15:00:53
【问题描述】:

我有一个很好的错误,特别是在慢速设备中。 我有一个类似于 App Store 应用程序中的 UITableView jusk,底部有一个加载更多按钮。 当它被按下时,我从服务器加载新信息,设置数组,然后重新加载表格视图。在该信息中也是表格行中显示的每个对象的图像的 url,所以当我们得到它时,我们开始下载图像。加载图像时,我重新加载对象的行。

[self.searchResultsTableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: path] withRowAnimation: UITableViewRowAnimationNone];

问题出现在重新加载行时,因为图像已下载,并且整个表正在这样做,因为用户按下了加载更多按钮并获得了更多信息。然后我得到这个错误:

Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (140) must be equal to the number of rows contained in that section before the update (125), plus or minus the number of rows inserted or deleted from that section (1 inserted, 1 deleted).

这是完全不稳定的,在更新新图像行时表格被放大了。 我的问题是:如何锁定它,以便在重新加载整个表之前不重新加载该行?它会像 table.isReloading 这样的东西。我尝试使用布尔锁,并在主线程中执行这两个操作,但它没有工作...... 非常感谢。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview crash


    【解决方案1】:

    嗯,对文档的一些研究让这一切变得更加清晰。

    reloadRowsAtIndexPaths:withRowAnimation:如果要提醒用户单元格的值正在更改,请调用此方法。但是,如果通知用户并不重要(也就是说,您只想更改单元格显示的值),您可以获取特定行的单元格并设置其新值。

    这就是我所做的,我得到了单元格并为图像设置了新值,而不是重新加载整个图像。我想它也更有效:

    AHMyTableViewCell *cell = (AHMyTableViewCell *) [self.myTableView cellForRowAtIndexPath:path];
    
                    if ((cell != nil) && ([cell  isKindOfClass:[AHMyTableViewCell class]]))
                        cell.myImageView.image = image;
    

    它现在不会崩溃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多