[英]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
.
Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on.
调用此方法以重新加载用于构造表的所有数据,包括单元格,节的页眉和页脚,索引数组等。 For efficiency, the table view redisplays only those rows that are visible.
为了提高效率,表视图仅重新显示那些可见的行。 It adjusts offsets if the table shrinks as a result of the reload.
如果表由于重新加载而缩小,则会调整偏移量。 The table view's delegate or data source calls this method when it wants the table view to completely reload its data.
当表视图的委托或数据源希望表视图完全重新加载其数据时,将调用此方法。 It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates
不应在插入或删除行的方法中调用它,尤其是在通过调用beginUpdates和endUpdates实现的动画块中
According to apples documentation, reloadData only reloads visible cells. 根据apples文档,reloadData仅重新加载可见的单元格。 This could be a problem if you are not using cell identifiers properly.
如果您没有正确使用单元格标识符,则可能会出现问题。
This still could be a threading issue. 这仍然可能是线程问题。 Check to see if you're running on the main thread before calling reloadData, and if you're not, run a dispatch_sync on the main queue.
在调用reloadData之前,检查是否在主线程上运行,如果不是,请在主队列上运行dispatch_sync。
If you try to run dispatch_anything on the main queue when you're already on the main queue the app will quit. 如果您已经在主队列中时尝试在主队列上运行dispatch_anything,则该应用程序将退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.