Я не могу понять, почему дополнительные ячейки создаются и отображаются при прокрутке или иногда, когда я отклоняю другой контроллер представления для просмотра ячеек.
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger tmpIndex = indexPath.row+1; //addd 1 because userDetail is first element
if ([self.model.order[tmpIndex] isKindOfClass:[Products class]])
{
Products *products = [self.model.order objectAtIndex:tmpIndex];
if ([[products display] isEqualToString:kACTIVITY_GRID_CELL_ID])
{
ActivityCollectionViewGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kACTIVITY_GRID_CELL_ID forIndexPath:indexPath];
cell.data = products;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
else
{
ActivityCollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kACTIVITY_LIST_CELL_ID forIndexPath:indexPath];
cell.data = products;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
}
else
{
OrderHeaders *orderHeaderBaskets = [self.model.order objectAtIndex:tmpIndex];
ActivityCollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kACTIVITY_LIST_CELL_ID forIndexPath:indexPath];
cell.data = orderHeaderBaskets;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
}
Насколько я понимаю, он добавляет только дополнительные пустые ячейки для этой части кода:
else
{
ActivityCollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kACTIVITY_LIST_CELL_ID forIndexPath:indexPath];
cell.data = products;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
}
else
{
OrderHeaders *orderHeaderBaskets = [self.model.order objectAtIndex:tmpIndex];
ActivityCollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kACTIVITY_LIST_CELL_ID forIndexPath:indexPath];
cell.data = orderHeaderBaskets;
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
}
Может ли это быть потому, что я использую dequeueReusableCellWithReuseIdentifier
несколько раз?Или это что-то еще вызывает?
Также есть ли способ проверить и удалить лишние ячейки?