OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何在 UICollectionView 的部分中自动分组项目? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:39
标题: iphone - 如何在 UICollectionView 的部分中自动分组项目?

我在 UICollectionView 中有固定数量的部分

-(NSInteger)numberOfSectionsInCollectionViewUICollectionView *)collectionView{

return 3;

}   

每个部分的项目数量固定

-(NSInteger)collectionViewUICollectionView *)collectionView numberOfItemsInSectionNSInteger)section {

return 9;

}

前 9 个项目通过第一部分中的 plist(使用 cellForItemAtIndexPath)正确显示。但是,第二部分和第三部分仅显示第一部分中的项目,而不是显示所需的项目。

所以,我正在尝试显示 plist 中的所有项目,并将它们自动分组为部分(9 个项目)。

我是 Objective-C 的新手,并且已经为此苦苦挣扎了很长一段时间,因此非常感谢您的帮助。

-(UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath{


        xx.image = [UIImage imageNamed:[imagePath objectAtIndex:indexPath.item]];


    }



Best Answer-推荐答案


你可以试试这个方法。

你需要这样指定索引路径。

 xx.image = [UIImage imageNamed:[imagePath objectAtIndex:indexPath.section * number of sections + indexpath.row]];

希望对你有所帮助。

关于iphone - 如何在 UICollectionView 的部分中自动分组项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18869881/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4