Я создаю страницу в своем приложении, где сегментированный элемент управления показывает два разных представления коллекции. Данные для CV поступают из API, который содержит два массива разной длины.
Моя проблема заключается в том, что первое представление коллекции имеет больше элементов в массиве, чем второе, а второе представление коллекции выполняет итерацию через cellAtIndexPath больше раз, чем требуется, и, следовательно, возвращает ошибку * Завершение приложения из-за необработанного исключения ' NSRangeException", причина: "-[__NSCFArray objectAtIndex:]: индекс (1) за пределами (1)"
Кто-нибудь может мне помочь?
Спасибо
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
DataStore *ds = [DataStore sharedDataStore];
if (self.cvActive) {
return ds.arLikesActive.count;
}
else {
return ds.arLikesExpired.count;
}
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
DataStore *ds = [DataStore sharedDataStore];
if (collectionView == self.cvActive) {
CollectionViewCellLikedActive *cell = (CollectionViewCellLikedActive *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
self.dProductActive = ds.arLikesActive[indexPath.item];
cell.ivActiveProduct.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.dProductActive[@"ImageURL"]]]];
return cell;
}
else {
CollectionViewCellLikedWhereAreTheyNow *cell = (CollectionViewCellLikedWhereAreTheyNow *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
self.dProductInactive = ds.arLikesExpired[indexPath.item];
cell.ivWhereAreTheyNowProduct.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.dProductInactive[@"ImageURL"]]]];
return cell;
}