因為現(xiàn)在swift越來月主流,項目新建文件已經全面改為swift,其中踩了不少的坑
collectionView移除數(shù)據(jù)時reloadData后
在iOS版本 > 13.0,機型:iPhone 7Plus上可以正常運行
在iOS版本 = 10.1.1,機型:iPad,上報錯崩潰
報錯刷新UICollectionView的布局問題:UICollectionView received layout attributes for a cell with an index path that does not exist
這個錯誤的原因主要是已經布局后的layout,刷新表時(collectionView.reloadData() )更改了section的數(shù)據(jù)源,導致從緩存layout獲取時index錯誤
既然知道錯誤原因就好解決了,讓layout從新初始化就行
代碼如下
collectionView.reloadData()
collectionView.collectionViewLayout.invalidateLayout()