我在iOS7
上有UICollectionView
,它在密集滾動時隨機崩潰。我啓用殭屍和發現,它給了我一個錯誤說:UICollectionView由於突出顯示的問題而隨機崩潰
*** -[NSIndexPath section]: message sent to deallocated instance 0x17dbc970
我相信這是由於蘋果的錯誤描述here。顯然,當有人在快速滾動的同時突出顯示某個單元格時,該應用程序會崩潰,然後當操作系統從屏幕移出並停止存在時,該操作系統會嘗試忽略它。建議的解決方案是禁用單元格的userInteractionEnabled
屬性,然後使用UIGestureRecogniser
處理選擇。
有沒有其他人面臨同樣的問題?此外,我試圖取消設置userInteractionEnabled
屬性並使用手勢識別器,但這似乎不起作用。任何想法如何我可以解決這個問題?
EDIT:代碼加在請求
-(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:多個代碼..
我所定義的GalleryCell
重用如下:
[self.flowCollection registerNib:[UINib nibWithNibName:@"Thumbs_Cell" bundle:nil] forCellWithReuseIdentifier:@"Gallery_Cell"];
的GalleryCell類實施是:
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]; // SDWebImage method to cancel ongoing image load
}
你一個數據加載到從核心數據細胞? 'cellForRowAtIndexPath:'正在工作時可能會發生這種崩潰。 –
我正在使用SDWebImage將圖像加載到Internet的單元格中。 –
所以你應該小心使用它,因爲每次單元變得可見時,'UICollectionView'調用'cellForRowAtIndexPath:'。 –