UICollectionView last cell not aligned

浪子不回头ぞ 提交于 2019-12-05 15:02:31

I had the same issue, in my case what helped was simply remove prototype cell items from UICollectionView in UI Builder and use UICollectionViewCell xib instead by creating xib and registering it as a cell view nib somewhere in viewDidLoad:

[collectionView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellWithReuseIdentifier:@"CustomCellIdentifier"];

and later in cellForItemAtIndexPath:

CustomCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCellIdentifier" forIndexPath:indexPath];

Sometimes, based on my own experience, iOS don't align properly the last cell on a UICollectionView.

To avoid that, you can add a new cell at last position on your dataSource, and set its height as 0. With that 'solution', the wrong-aligned cell will be that last cell that is not important for you and, in practise, the cell will be invisible.

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