【问题标题】:How to create UICollectionView with alternating cell amount layout?如何使用交替单元格数量布局创建 UICollectionView?
【发布时间】:2014-10-06 02:44:18
【问题描述】:
我正在开发一个 iPad 应用程序,它使用 UICollectionView 来显示公司的产品列表。我要使用的单元格布局是在具有 1 个图像和 2 个图像的行之间交替,例如第一行 1 个图像、第二行 2 个图像、第三行 1 个图像......等等,但我就是不知道如何在代码中执行此操作。
那么有人可以帮我解决这个问题吗?
【问题讨论】:
标签:
objective-c
ios7
uicollectionview
uicollectionviewcell
【解决方案1】:
嘿伙计们,我设法让它与这段代码一起工作:
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 2;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 30;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Cells *cell;
if (indexPath.row %2) {
NSLog(@"%li", indexPath.row);
cell = [cv dequeueReusableCellWithReuseIdentifier:@"one" forIndexPath:indexPath];
cell.label.text = @"One";
cell.backgroundColor = [UIColor blueColor];
return cell;
} else {
NSLog(@"%li", indexPath.row);
cell = [cv dequeueReusableCellWithReuseIdentifier:@"two" forIndexPath:indexPath];
cell.labelA.text = @"Two";
cell.labelB.text = @"Two";
cell.backgroundColor = [UIColor redColor];
return cell;
}
}