为 UICollectionView 指定行号和列号 [英] Specify row and column number for UICollectionView
本文介绍了为 UICollectionView 指定行号和列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想展示一个 UICollectionView,它正好包含 2 行,每行 100 个单元格.
I want to show a UICollectionView which contains exactly 2 rows and 100 cells in each row.
// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 100;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 2;
}
// 3
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.lbl.text = @"Data";
return cell;
}
我得到了这个:
如何为 UICollectionView 指定行号?我想创建一个 2x100 的表.
How can I specify a row number for UICollectionView? I want to create a 2x100 table.
推荐答案
试试这个:
// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 2;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 100;
}
// 3
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.lbl.text = @"Data";
return cell;
}
这篇关于为 UICollectionView 指定行号和列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文