问题描述
调用 - [UICollectionView reloadData]
后,显示单元格需要一些时间,因此在调用 reloadData $后立即选择一个项目c $ c>不起作用。有没有办法在
reloadData
之后立即选择一个项目?
After calling -[UICollectionView reloadData]
it takes some time for cells to be displayed, so selecting an item immediately after calling reloadData
does not work. Is there a way to select an item immediately after reloadData
?
推荐答案
按照,我发现在 layoutIfNeeded code> reloadData 似乎在我对collectionView执行其他操作之前有效地刷新重新加载:
Along the lines of this answer I found that calling layoutIfNeeded
after reloadData
seemed to effectively 'flush' the reload before I do other things to the collectionView:
[self.collectionView reloadData];
[self.collectionView layoutIfNeeded];
...
在页面上我找到了这个解决方案,一些评论者指出它没有'在iOS 9上为他们工作,但对我来说没问题,所以你的里程可能会有所不同。
On the page I found this solution, some commenters indicated it didn't work for them on iOS 9, but it's been fine for me so your mileage may vary.
这篇关于uicollectionview在reloaddata之后立即选择一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!