因未捕获的异常而终止应用程序' NSInternalInconsistency:

时间:2014-05-05 06:36:28

标签: ios uitableview

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DataCell1 *cell1=[self.tblView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
    DataCell2 *cell2=[self.tblView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
    DataCell3 *cell3=[self.tblView dequeueReusableCellWithIdentifier:@"Cell3" forIndexPath:indexPath];
   // UITableViewCell *cell=[self.tblView dequeueReusableCellWithIdentifier:<#(NSString *)#> forIndexPath:<#(NSIndexPath *)#>]
    switch (indexPath.section) {
            NSLog(@"%i",indexPath.section);
        case 0:
            if(cell1!=nil)
                cell1.lblShowCell1.text=@"abc";

            return cell1;
            break;
        case 1:

            if(cell2!=nil)
                cell2.lblShow2.text=@"def";

            return cell2;
            break;
        case 2:
            if(cell3!=nil)

                cell3.lblShow3.text=@"xyz";

        default:
            break;
    }
    return nil;

}

1 个答案:

答案 0 :(得分:0)

 DataCell1 *cell1=[self.tblView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
    DataCell2 *cell2=[self.tblView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
    DataCell3 *cell3=[self.tblView dequeueReusableCellWithIdentifier:@"Cell3" forIndexPath:indexPath];

在上面的行中,您尝试使用单个索引路径将所有单元格出列。您应该检查索引路径并相应地使单元格出列。

例如:

if(indexPath.row == 0){
     DataCell1 *cell1=[self.tblView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
}
else if(indexPath.row == 1){
     DataCell1 *cell1=[self.tblView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
}

你回来没事了。你返回Cell