I have a UICollectionView on iOS7 that accidentally crashes when scrolling intensively. I turned on the zombies and found that this gives me an error:
*** -[NSIndexPath section]: message sent to deallocated instance 0x17dbc970
I believe this is due to the Apple error described here . Apparently, the application crashes when someone selects a cell while scrolling quickly, and then the OS tries to highlight it when it exits the screen, when it ceases to exist. The proposed solution is to disable the userInteractionEnabled property of the cell, and then handle the selection using UIGestureRecogniser .
Has anyone else encountered this same problem? Also, I tried disabling the userInteractionEnabled property and using a gesture recognizer, but this does not seem to work. Any idea how I can fix this?
EDIT : code added on request
-(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; if ([[[SDWebImageManager sharedManager] imageCache] imageFromDiskCacheForKey:[self cacheKeyForURL:mainImageURL]] == nil) { [cell.image setImageWithURL:mainImageURL placeholderImage:nil]; }else{ [cell.image setImage:[[[SDWebImageManager sharedManager] imageCache] imageFromDiskCacheForKey:[self cacheKeyForURL:mainImageURL]]]; } } return cell; }
EDIT : more code ..
I defined GalleryCell for reuse as follows:
[self.flowCollection registerNib:[UINib nibWithNibName:@"Thumbs_Cell" bundle:nil] forCellWithReuseIdentifier:@"Gallery_Cell"];
GalleryCell class implementation:
GalleryCell.h
@interface GalleryCell : UICollectionViewCell @property (nonatomic, retain) IBOutlet UIImageView *image; @end
GalleryCell.m
@implementation GalleryCell @synthesize image; -(void) setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; [self setNeedsDisplay]; } -(void)prepareForReuse { [super prepareForReuse]; [self.image cancelCurrentImageLoad];
source share