我们正在使用- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
方法来检索特定索引路径处的单元格。- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果单元格不可见或 indexPath 超出范围,将返回表示表格单元格的对象或 nil。但是重复调用会- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
导致 NSRange 异常。可能是什么原因?
NSIndexPath *ip = [NSIndexPath indexPathForRow:index inSection:0];
CustomCell *cell = (CustomCell *)[tableview_ cellForRowAtIndexPath:ip];
代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = nil;
static NSString *cellIdentifier = @"Cell";
cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
ImageCache *imageCache = [[ImageCache alloc]initWithUrl:sentCard.sentImage];
UIImage *cachedImage = [imageCache fetchImageFromCache];
if (cachedImage!=nil) {
cell.cardImage.image = [Utility scaleImageToSize:cell.cardImage.frame.size image:cachedImage];
[cell.loadingIndicator stopAnimating];
}
else {
imageCache.cacheDelegate = self;
imageCache.cacheDuration = 24.0;
[imageCache fetchImage];
}
return cell;
}