gpt4 book ai didi

ios - 为 UICollectionView 指定行号和列号

转载 作者:IT王子 更新时间:2023-10-29 08:10:03 27 4
gpt4 key购买 nike

我想显示一个 UICollectionView,它恰好包含 2 行,每行有 100 个单元格。

// 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;
}

我得到这个:

enter image description here

如何为 UICollectionView 指定行号?我想创建一个 2x100 的表。

最佳答案

试试这个:

// 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;
}

关于ios - 为 UICollectionView 指定行号和列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19010335/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com