0

以前この質問をしたことがありますが、より明確にプロジェクトの状況をお知らせします

サブビューとしてテーブルビューを追加し、4つのセクションを持つテーブルビューと、それぞれ1,4(動的)、3、2行を持つセクションを追加しました。セクション= 0、テキストフィールドがあります、セクション= 2 2スイッチボタン、セクション= 3両方の行に背景色があります。これらのすべてのオブジェクトは、プログラムではなく Xib を介して追加しました。下にスクロールすると、セクション 0,1 にカラーが表示され、セクション 1,2 にボタンが表示されます。

if (indexPath.section==0) {
  if (indexPath.row==0) {
     self.enterNameTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
     self.enterNameTextField.clearsOnBeginEditing =YES;
     self.enterNameTextField.delegate = self;
     self.enterNameTextField.tag=indexPath.row;
     self.enterNameTextField.placeholder=@"Enter youe name";
     self.enterNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     [cell.contentView addSubview:  self.enterNameTextField];

     }
     else {
            [self.enterNameTextField removeFromSuperview];
     }            
    }    
 if (indexPath.section==1) {
        NSInteger ii=[self.sectionRows count];
        if(indexPath.row== ii) {
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
            cell.textLabel.text=@"Work Out Detail";
        }
        else {
            NSArray *kk=[self.sectionRows objectAtIndex:indexPath.row];
            NSLog(@"..%@/...index=%d",[self.sectionRows objectAtIndex:indexPath.row],indexPath.row);
            cell.textLabel.text=[NSString stringWithFormat:@"%@.%@",[kk objectAtIndex:2],[kk objectAtIndex:0 ]];
        }
    }
  if (indexPath.section==2) {    
    if (indexPath.row==0) {
            NSInteger taskData;
            taskData=  [[NSUserDefaults standardUserDefaults]integerForKey:@"RepetitionCheckMark"];
            self.repitiiondata=[self.listOfRepititionContent objectAtIndex:taskData];
            cell.textLabel.text=@"Repetitions";
            cell.detailTextLabel.text=self.repitiiondata;
            NSLog(@"cvxcv%@",self.repitiiondata);
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }
    if (indexPath.row==1) {
            cell.accessoryView=[[UIView alloc]initWithFrame:self.coolDownSwitch.frame];
            cell.accessoryView=[[UIView alloc]initWithFrame:self.warmUpSwitch.frame];
            cell.textLabel.text=@"Warm Up(5 min.)";
            int pp=[ self.wrmUpString integerValue];

            if(pp==1) {    
                [self.warmUpSwitch setOn:YES];
            }                
           else {
             [self.warmUpSwitch setOn:NO];
           }
           [cell.accessoryView addSubview:self.warmUpSwitch];

        }

   if (indexPath.row==2) {
            cell.accessoryView=[[UIView alloc]initWithFrame:self.coolDownSwitch.frame];
            [cell.accessoryView addSubview:self.coolDownSwitch];
            int pp=[ self.coolDwnString integerValue]
            if(pp==1) {                    
                [self.coolDownSwitch setOn:YES];
            }
            else {
                [self.coolDownSwitch setOn:NO];
            }
            cell.textLabel.text=@"Cool Down(5 min.)";  
            [cell.accessoryView addSubview:self.coolDownSwitch];
        }
    }        
}   
if (indexPath.section==3) {        
    if (indexPath.row==0) {
        cell.textLabel.text=@"            SAVE CONTENT";
        cell.textLabel.textColor=[UIColor whiteColor];
        cell.backgroundColor=[UIColor redColor];   
    }
    else {
         cell.textLabel.text=@"            DELETE CONTENT";
         cell.textLabel.textColor=[UIColor whiteColor];    
         cell.backgroundColor=[UIColor blackColor];    
     }
  }      
 }

return cell;
}
4

2 に答える 2

1

I found difficult to understand your doubt. But try this. Give different cellidentifier in xib. And use diff cell in diff sections Problem is section 0 is reusing cell from section 2.

于 2013-02-27T05:22:37.087 に答える
0

セル識別子をnilとして設定します。 これはあなたを助けます。

于 2013-02-27T05:36:41.547 に答える