gpt4 book ai didi

ios - UICollectionView cellForItemAtIndexPath 为零

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

我有一个更新现有 UICollectionView 的函数。UICollectionView 已创建,我可以看到它,但是当我想访问它的单元格以更新它时,它们为零。

-(void)finishExam{

for (int i = 0; i < [self.questionsOverviewCollection numberOfItemsInSection:0]; i++) {

NSLog(@"self.questionsOverviewCollection - %@",self.questionsOverviewCollection);
NSLog(@"cell - %@",[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]);
NSLog(@"overviewCell - %@",(OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]);
NSLog(@"numOfCells - %d", [self.questionsOverviewCollection numberOfItemsInSection:0]);

OverviewCell *cell = (OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[cell finishExam];
}
}


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

OverviewCell *cell = (OverviewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

[cell someSetUp];

return cell;
}

日志:

self.questionsOverviewCollection - <UICollectionView: 0xa1abc00; frame = (14 219; 217 441); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0xe0617a0>; layer = <CALayer: 0xe0bbb00>; contentOffset: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0xe0cc3f0>
cell - (null)
overviewCell - (null)
numOfCells - 30

最佳答案

来自UICollectionView文档(强调我自己的)

Return Value
The cell object at the corresponding index path or nil if the cell is not visible or indexPath is out of range.

您应该更新为 View 提供数据的基础模型。

关于ios - UICollectionView cellForItemAtIndexPath 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22861804/

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