セグメント化されたコントロールが 2 つの異なるコレクションビューを表示するページをアプリで作成しています。CV のデータは、2 つの異なる長さの配列を含む API から取得されます。
私の問題は、最初の Collection View の配列に 2 番目の Collection View よりも多くのアイテムがあり、2 番目の CollectionView が必要以上に cellAtIndexPath を反復処理しているため、エラーが返されることです[__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;
}