簡體   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