由于未捕获的异常终止应用程序' NSRangeException',原因:' *** - [__ NSArrayM objectAtIndex:]:索引5超出边界[0 .. 4]'

时间:2015-11-17 11:05:31

标签: objective-c nsarray nsrangeexception

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    SimpleeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.TitleLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.PlaceLabel.text = [placeData objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
    cell.RankingsLabel.text = [rankingsData objectAtIndex:indexPath.row];
    cell.StatusLabel.text = [statusData objectAtIndex:indexPath.row];
    cell.DistanceLabel.text = [distanceData objectAtIndex:indexPath.row];



    return cell;
}

我该如何解决这个错误?

1 个答案:

答案 0 :(得分:-1)

您的tableDataplaceDataXXXdata的计数小于您的手机数量。
你可以在这些方面做一些断点。
cell.TitleLabel.text = [tableData objectAtIndex:indexPath.row]; cell.PlaceLabel.text = [placeData objectAtIndex:indexPath.row]; cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]]; cell.RankingsLabel.text = [rankingsData objectAtIndex:indexPath.row]; cell.StatusLabel.text = [statusData objectAtIndex:indexPath.row]; cell.DistanceLabel.text = [distanceData objectAtIndex:indexPath.row]; 您也可以使用tableData.count查看它是否超出范围。

相关问题