繁体   English   中英

cellForRowAtIndexPath:被立即调用,而numberOfRowsInSection:不被调用

[英]cellForRowAtIndexPath: being called immediately while numberOfRowsInSection: is not called

I've encountered this issue a few times after the reloadData method on a UITableView is invoked, and I haven't figured out why?

This is a problem because if the data of table view is updated, the tableview will unnecessarily query the cell on a non-existent row. It is non-existent, because the numberOfRowsInSection: somehow is not called before this is happening.

Is it affected by how the reloadData method is being invoked? (It is invoked on the main thread, not anywhere else).

Update:

cellForRowAtIndexPath: could be invoked by other means such as querying visibleCells. It may be the case that this isn't part of reloadData.

调用此方法以重新加载用于构造表的所有数据,包括单元格,节的页眉和页脚,索引数组等。 为了提高效率,表视图仅重新显示那些可见的行。 如果表由于重新加载而缩小,则会调整偏移量。 当表视图的委托或数据源希望表视图完全重新加载其数据时,将调用此方法。 不应在插入或删除行的方法中调用它,尤其是在通过调用beginUpdates和endUpdates实现的动画块中

根据apples文档,reloadData仅重新加载可见的单元格。 如果您没有正确使用单元格标识符,则可能会出现问题。

这仍然可能是线程问题。 在调用reloadData之前,检查是否在主线程上运行,如果不是,请在主队列上运行dispatch_sync。

如果您已经在主队列中时尝试在主队列上运行dispatch_anything,则该应用程序将退出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM