我在 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/