【发布时间】:2013-07-19 10:29:55
【问题描述】:
我们正在使用- (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;
}
【问题讨论】:
-
你会展示你的
cellForRowATIndexPath:方法吗? -
你没有返回任何单元格.. ;) 这是一个错字,不是你的错误的原因
-
@Jesly Varghese 抱歉,编辑帖子时出错。
-
请发布完整的错误信息。
标签: ios uitableview