0

こんにちは、それは私が直面している奇妙な問題です。私はUItableCustomCellsセクションのグループ化された 1 つの 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 に答える