我正在我的应用程序中创建一个页面,其中分段控件显示两个不同的集合视图。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;
}