0

嗨朋友们,这是我面临的一个奇怪问题,我UItableCustomCells在一个分组的 TableView 中使用多个部分。

我只能选择第一个部分的行,然后当我单击另一个部分的行时,它的选择方法不起作用,我不明白哪里出错了,我的cellForRowAtIndexPath代码如下:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    NSString *CellIdentifier =[NSString stringWithFormat:@"%d",indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //if (cell == nil) {




    if(indexPath.section==0)
    {
        if(indexPath.row==0)
        {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell1" owner:self options:nil];
            cell = self.Cell1;
            self.Cell1 = nil;

            txtincidentName = (UITextField*)[cell.contentView viewWithTag:1];





        }
        else if(indexPath.row==1)
        {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell2" owner:self options:nil];
            cell = self.Cell2;
            self.Cell2 = nil;
             lblDatefirst = (UILabel*)[cell.contentView viewWithTag:2];
            btnCalfirst  = (UIButton*)[cell.contentView viewWithTag:3];
            lblTimeFirst = (UILabel*)[cell.contentView viewWithTag:4];

        }
        else if(indexPath.row==2)
        {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell2" owner:self options:nil];
            cell = self.Cell2;
            self.Cell2 = nil;

            lblDatefirst = (UILabel*)[cell.contentView viewWithTag:2];
            btnCalfirst  = (UIButton*)[cell.contentView viewWithTag:3];
            lblTimeFirst = (UILabel*)[cell.contentView viewWithTag:4];
            lblInciTime =(UILabel*)[cell.contentView viewWithTag:9];
            lblInciTime.text=@"Date/Time";

        }

    }
    else if(indexPath.section==1)
    {
        if(indexPath.row==0)
        {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell3" owner:self options:nil];
            cell = self.Cell3;
            self.Cell3 = nil;

            btndropDown1 = (UIButton*)[cell.contentView viewWithTag:5];
            btndropDown2  = (UIButton*)[cell.contentView viewWithTag:6];
            btndropDown3 = (UIButton*)[cell.contentView viewWithTag:7];

        }
        else if(indexPath.row==1)
        {
            [[NSBundle mainBundle]loadNibNamed:@"CustomCell4" owner:self options:nil];
            cell = self.Cell4;
            self.Cell4 = nil;
             txtViewofdetails = (UITextView*)[cell.contentView viewWithTag:7];
        }


    }


        return cell;


}

模拟器图像

在此处输入图像描述

请帮助和指导谢谢..

4

2 回答 2

0

不要像这样从笔尖加载细胞。而是在 NIB 中使用重用标识符注册单元。这将导致出队根据标识符选择正确的单元格原型。

您当前的方法很可能会弄乱表格视图的触摸处理。

于 2012-12-13T06:17:35.043 回答
0

嘿试试这种类型的概念和代码流

   NSString *CellIdentifier =[NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell1" owner:self options:nil];

        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (CustomCell1 *) currentObject;
                break;
            }
        }
    }
于 2012-12-13T06:31:28.277 回答