同时重新加载行和整个表时崩溃
我这里有一个很好的错误,特别是在慢速设备中。 我有一个 UITableView jusk,就像 App Store 应用程序中的那样,底部有一个“加载更多”按钮。 当按下它时,我从服务器加载新信息,设置数组,然后重新加载表视图。该信息中还包含表行中显示的每个对象的图像 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 这样的东西会很好。我尝试使用布尔锁,并在主线程中执行这两个操作,但它不起作用...... 多谢。
I have a nice bug here, specially in slow devices.
I have a UITableView jusk like the ones in the App Store app, with a Load More button at the bottom.
When it is pressed, I load the new info from the server, set the array, and reload the table view. In that info is also the url of the image for each object displayed in the table rows, so when we got it we start donwloading the image. When the image is loaded, I reload the row of the object.
[self.searchResultsTableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: path] withRowAnimation: UITableViewRowAnimationNone];
The problem comes when the row is being reloading because the image was downloaded, and the whole table is doing so cause the user pressed the load more button and more info was gotten. Then I get this error:
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).
Which is perfectly understable, the table was enlarged while the new image row was being updated.
My question is: how can lock it so I do not reload that row until the whole table is reloaded? It would nice something like table.isReloading. I try with a boolean lock, and doing both actions in the main thread, but it did not work ...
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,文档中的一些研究让这一切有了更多的了解。
这就是我所做的,我获取了单元格并设置了图像的新值,而不是重新加载整个图像。我想它也更有效:
它现在不会崩溃。
Well, a little research in the doc put some more light in all this.
And that is what I did, I got the cell and set the new value for image, instead of reloading the whole of it. I guess it is more efficient also:
It does not crash now.