I have a UICollectionView that scrolls vertically. The first cell contains another UICollectionView that scrolls horizontally.
In random cases, the horizontal UICollectionView loads the cell and does not display it. So, I can see a couple of cells, empty space and a few more cells. Itβs hard for me to understand the reason for this.
The code is as follows:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView.tag == 1) {
if (indexPath.section == 1) {
} else if (collectionView.tag == 999) {
HorizontalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell999" forIndexPath:indexPath];
[self addBorderToCellImageView:cell.imageView];
[self updateHorizontalCell:cell forIndexPath:indexPath];
return cell;
}
return [[UICollectionViewCell alloc] init];
}
second part:
- (void)updateHorizontalCell:(HorizontalCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
id obj = self.horizontalProductDataSource[indexPath.row];
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);
}];
}
any help would be awesome!
source
share