iphone - 如何自动对 UICollectionView 中的项目进行分组?

标签 iphone ios objective-c uicollectionview

我在 UICollectionView 中有固定数量的 Section

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

return 3;

}   

每个部分固定数量的项目

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

return 9;

}

前 9 个项目在第一部分中通过 plist(带有 cellForItemAtIndexPath)正确显示。然而,第二和第三部分只显示第一部分中的项目,而不是显示所需的项目。

因此,我试图显示 plist 中的所有项目,并将它们自动分组到部分(9 个项目)中。

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

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


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


    }

最佳答案

你可以试试这个。

您需要以这种方式指定索引路径。

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

希望对你有帮助。

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

相关文章:

iphone - 将设备添加到团队配置文件

objective-c - NSString 和指针

iphone - 如何自定义 UITabBar 文本标签?

iphone - iOS 上可以使用本地存储来持久化缓存吗

iphone - Xcode 4.2 测试版和 iOS 4.2

ios - 如何在 Cordova 中显示照片库权限对话框?

ios - Swift:删除状态栏时出错

javascript - 在没有 jQuery 的情况下防止双击缩放

objective-c - 透明图像叠加在下方 View 上

c++ - Objective-C++ 为 iPhone 编译,但不是模拟器