UICollectionView mysterious crash

I have a UICollectionView where I fill cells with images downloaded from the Internet. For this I use SDWebImage . My code is as follows:

 -(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ NSString *CellIdentifier = @"Gallery_Cell"; GalleryCell *cell= (GalleryCell *)[self.flowCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; if (indexPath.row < self.collectionData.count) { CellDetails *dets = [self.collectionData objectAtIndex:indexPath.row]; NSURL *mainImageURL = [NSURL URLWithString:dets.imageURL]; cell.image.contentMode = UIViewContentModeScaleAspectFill; cell.image.clipsToBounds = YES; [cell.image setImageWithURL:mainImageURL placeholderImage:nil]; } return cell; } 

I believe I set it right. But the application unexpectedly resets ( EXC_BAD_ACCESS ), sometimes leaving this stack trace:

enter image description here

There is no other message in the log area. I tried to set an exception checkpoint, but every time this failure occurs, this stack trace is displayed. Does anyone know what could be the problem?

+6
source share
3 answers

If someone is looking for an answer, I solved the problem and answered one of my questions related to the same problem. Here you can find. Hope this helps!

+2
source

Have you registered your CollectionViewCells?

If you did this,

 dequeueReusableCellWithReuseIdentifier:forIndexPath: 

should create a cell for you if there is no cell to be reused.

IN

 - (void)viewDidLoad 

register your cells with CollectionView

 UINib *galleryCellNib = [UINib nibWithNibName:@"GalleryCell" bundle:nil]; [self.collectionView registerNib:galleryCellNib forCellWithReuseIdentifier:@"Gallery_Cell"]; 

or

 [self.collectionView registerClass:[GalleryCell class] forCellWithReuseIdentifier:@"Gallery_Cell"]; 

Depending on whether you use xib or just a class

+1
source

This can also happen when one of the connections in the InterfaceBuilder is no longer valid (when setting up the cell class - inheriting from UITableViewCell or UICollectionViewCell). For example: if the name of the control in the file has changed without updating the connection to it in InterfaceBuilder.

0
source

Source: https://habr.com/ru/post/959480/


All Articles