我把UICollectionView放在UICollectionView标头中,标题内的图像直到我写完才出现:
override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
let index = NSIndexPath(item: 0, section: 0)
self.collectionView?.reloadItems(at: [index as IndexPath])
}
但模拟器有时崩溃就是这条线!
那么任何建议,想法?
答案 0 :(得分:0)
我通过检查可见单元格的索引来解决它:
let Visibleindex = collectionView.indexPathsForVisibleItems
for index in 0..<Visibleindex.count {
if index == 0 {
let index = NSIndexPath(item: 0, section: 0)
self.collectionView?.reloadItems(at: [index as IndexPath])
}
}