Подтвердить что ты не робот

UICollectionView cellForItemAtIndexPath - nil

У меня есть функция, которая обновляет существующий 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;
}

Log:

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
4b9b3361

Ответ 1

Из UICollectionView документов (выделение мое собственное)

Возвращаемое значение
Объект ячейки на соответствующем пути индекса или nil, если ячейка не видна или indexPath вне диапазона.

Вы должны обновить базовую модель, которая предоставляет данные для представлений.

Ответ 2

Попробуйте следующее:

[collectionView reloadData];
[collectionView layoutIfNeeded];