Я пытаюсь прокрутить мой UICollectionView до вершины с помощью кода. Я называю этот метод:scrollToItemAtIndexPath вызывает приложение для сбоя
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
крушения:
** Нагрузочного приложение из-за неперехваченное исключение «NSInternalInconsistencyException», причина: «Источник данных Представления коллекции не вернулся действительная ячейкой из - collectionView: cellForItemAtIndexPath: для указательного пути {длина = 2, путь = 0 - 0} '
Не слишком уверен, как это исправить?
Спасибо!
Редактировать
Вот моя коллекция метод зрения - я загружаю три различных типа клеток, если условие:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *tableCellIdentifier = @"TableItemCell";
static NSString *gridCellIdentifier = @"GridItemCell";
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
if (indexPath.item < [self.tradeSearchArray count]){
if (self.gridLayoutActive == NO){
self.switchToTableLayout = NO;
BBItemTableViewCell *tableItemCell = [collectionView dequeueReusableCellWithReuseIdentifier:tableCellIdentifier forIndexPath:indexPath];
if ([self.tradeSearchArray count] > 0){
self.toolBarButtomItem.title = [NSString stringWithFormat:@"%d Results", self.searchResult.searchResults];
self.switchToTableLayout = NO;
tableItemCell.gridView = NO;
tableItemCell.backgroundColor = [UIColor whiteColor];
tableItemCell.item = self.tradeSearchArray[indexPath.row];
}
return tableItemCell;
}else
{
BBItemTableViewCell *gridItemCell= [collectionView dequeueReusableCellWithReuseIdentifier:gridCellIdentifier forIndexPath:indexPath];
if ([self.tradeSearchArray count] > 0){
self.toolBarButtomItem.title = [NSString stringWithFormat:@"%d Results", self.searchResult.searchResults];
self.switchToTableLayout = YES;
gridItemCell.gridView = YES;
gridItemCell.backgroundColor = [UIColor whiteColor];
gridItemCell.item = self.tradeSearchArray[indexPath.row];
}
return gridItemCell;
}
}else
{
BBLoaderCell *loaderCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LoaderCell" forIndexPath:indexPath];
loaderCell.backgroundColor = [UIColor clearColor];
if (self.maximumOffset - self.currentOffset <= 1000.0) {
[self loadMoreSearchResults];
if (self.loadingMore){
dispatch_async(dispatch_get_main_queue(), ^{
activityIndicator.hidden = NO;
[loaderCell.spinner startAnimating];
});
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
activityIndicator.hidden = YES;
[loaderCell.spinner stopAnimating];
});
}
return loaderCell;
}
}
return nil;
}
Перечитайте сообщение об ошибке и проверьте (и может быть здесь сообщение) код метода, который вызвал проблемы – Vladimir
вставьте свою коллекциюView: cellForItemAtIndexPath –
Обновлен вопрос с помощью метода просмотра коллекции. Спасибо, ребята – Tander