UICollectionView indexPathsForVisibleItems don't update new visible cells

你离开我真会死。 提交于 2019-12-03 12:56:49
jszumski

If you are targeting iOS 8.0 and above you should use collectionView:willDisplayCell:forItemAtIndexPath: to kick off your download. If using iOS 7.0 you should continue to use collectionView:cellForItemAtIndexPath:.

In your imageLoaderDidFinishDownloading: callback you should check to see if the index path in question is still visible. If it is, retrieve the corresponding cell and update its image view. If the cell isn't visible, then your work is done. Calling -reloadData for every image completion is doing a lot of expensive work and could have significant UX issues if your user is currently mid-scroll of the table and you reset its contents. You are also potentially doing the UIImageJPEGRepresentation() work many times, it would help your scrolling performance if you did this work once in imageLoaderDidFinishDownloading: and then cached it.

Since it looks like the callback happens on a background thread make sure you only manipulate the UICollectionView from the main thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!