У меня есть UICollectionView, который прокручивается вертикально. Первая ячейка содержит другой UICollectionView, который прокручивается по горизонтали.
В случайных случаях горизонтальный UICollectionView загружает ячейку и не отображает ее. Итак, я вижу пару ячеек, пустое пространство и еще несколько ячеек. Мне трудно определить причину этого.
Код выглядит так:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView.tag == 1) {
if (indexPath.section == 1) {
// do some stuff
} else if (collectionView.tag == 999) { // horizontal collection view
HorizontalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell999" forIndexPath:indexPath];
[self addBorderToCellImageView:cell.imageView];
[self updateHorizontalCell:cell forIndexPath:indexPath];
return cell;
}
return [[UICollectionViewCell alloc] init]; // in any case, return a cell.
}
вторая часть такова:
// updating cells for collectionView.tag = 999;
- (void)updateHorizontalCell:(HorizontalCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
id obj = self.horizontalProductDataSource[indexPath.row]; // use introspection, and act accordingly.
NSLog(@"section %ld, row %ld", (long)indexPath.section, (long)indexPath.row);
if ([obj isKindOfClass:[Product class]]) {
Product *wishListProduct = (Product *)obj;
cell.subtitle.hidden = YES;
cell.title.text = wishListProduct.name;
NSLog(@"from product: %@", wishListProduct.name);
NSLog(@"from cell: %@", cell.title.text);
cell.price.text = [NSString stringWithFormat:@"%.f %@", wishListProduct.totalPrice, NSLocalizedString(@"Shekel", nil)];
__weak HorizontalCell *weakCell = cell;
NSString *imageURL;
Image *image = [wishListProduct.pictuers lastObject];
imageURL = image.url;
[cell.imageView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:imageURL]]
placeholderImage:[UIImage imageNamed:@"Icon.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
weakCell.imageView.image = image;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
logIt(@"error while bringing photos into cells: %@", error);
}];
}
любая помощь будет потрясающей!