Ios cellForRowAtIndexPath中的NSRangeException

Ios cellForRowAtIndexPath中的NSRangeException,ios,uitableview,Ios,Uitableview,我们正在使用-(UITableViewCell*)cellforrowatinexpath:(nsindepath*)indepath方法检索特定索引路径上的单元格-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)indexPath将返回表示表中某个单元格的对象,如果该单元格不可见或indexPath超出范围,则返回nil。但是,重复调用-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexP

我们正在使用
-(UITableViewCell*)cellforrowatinexpath:(nsindepath*)indepath方法检索特定索引路径上的单元格
-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)indexPath
将返回表示表中某个单元格的对象,如果该单元格不可见或indexPath超出范围,则返回nil。但是,重复调用
-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)indexPath
会导致NSRange异常。原因可能是什么

NSIndexPath *ip = [NSIndexPath indexPathForRow:index inSection:0];
        CustomCell *cell = (CustomCell *)[tableview_ cellForRowAtIndexPath:ip];
代码


您请求的单元格尚未创建。例如,它应该在第一个单元格(索引0)上崩溃。一旦表格被填充,您应该请求一个单元格(也称为
cellforrowatinexpath
)。

查看此链接您是否会显示
cellforrowatinexpath:
方法?您不会返回任何单元格。)这是打字错误,不是你错误的原因though@JeslyVarghese抱歉,编辑post时出错。请发布完整的错误消息。UITableView文档指定-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)indexPath将返回表示表中某个单元格的对象,如果该单元格不可见或indexPath超出范围,则返回nil。因此,如果指定的索引路径中没有单元格,它将返回nil。但是,在这里调用(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)indexPath会产生NSRangeException。在
numberOfRowsInSection
上返回什么?它不会导致崩溃/范围异常,优雅地返回零崩溃的位置在哪里?
 - (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;
}