【发布时间】:2013-12-06 14:29:49
【问题描述】:
我有一个UICollectionView,我正在用从 Internet 下载的图像填充单元格。为此,我使用SDWebImage。我的代码如下所示:
-(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;
}
我相信我已正确设置。但应用程序完全随机崩溃 (EXC_BAD_ACCESS),有时会留下此堆栈跟踪:
日志区域中没有其他消息。我尝试设置异常断点,但每次发生此崩溃时,都会显示此堆栈跟踪。有谁知道可能是什么问题?
【问题讨论】:
-
异常断点在这里不起作用,因为这是一个 EXC_BAD_ACCESS。意味着它可能是分段错误/分段违规。很多机会成为悬空指针
-
好的。那么我该如何去寻找问题的根源呢?也许是僵尸对象?
-
我还没有使用集合视图,但你不应该在出列后检查单元格是否为空吗?如果没有,创建单元格?
-
如果随机崩溃总是发生在同一个堆栈崩溃(NSIndexPath indexAtPosition)中,或者如果它进入其他崩溃堆栈,您应该向我们准确说明。这将有助于理解真正的问题
-
但是,启用僵尸进行调试。那应该找到并修复丑鸭
标签: ios objective-c ios7 uicollectionview uicollectionviewcell