2013-02-27 63 views
0

我问这个问题以前,现在更清楚,我会让你知道我的项目对象在其他细胞行显示

我添加的表视图作为子视图,并具有4段和具有1节表视图的情况下, 4(动态),3,2行。 section = 0,textfield在那里,section = 2 2 switch button,section = 3两行都有背景色。 这些所有对象我通过Xib而不是以编程方式添加, 当我向下滚动colorse进入部分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; 
    [email protected]"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; 
      [email protected]"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]; 
      [email protected]"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]; 
      [email protected]"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]; 
      } 
      [email protected]"Cool Down(5 min.)"; 
      [cell.accessoryView addSubview:self.coolDownSwitch]; 
     } 
    }   
} 
if (indexPath.section==3) {   
    if (indexPath.row==0) { 
     [email protected]"   SAVE CONTENT"; 
     cell.textLabel.textColor=[UIColor whiteColor]; 
     cell.backgroundColor=[UIColor redColor]; 
    } 
    else { 
     [email protected]"   DELETE CONTENT"; 
     cell.textLabel.textColor=[UIColor whiteColor];  
     cell.backgroundColor=[UIColor blackColor];  
    } 
    }  
} 

return cell; 
} 
+0

TIPS:你应该添加单元格标记 – 2013-02-27 05:21:56

+0

你能显示整个cellforrow方法吗? – DivineDesert 2013-02-27 05:34:19

+0

嗨@RameshRajput,而不是工作indexpath.row,分配标签到uitableview中的每个原型单元格并使用它。 – 2013-02-27 05:49:24

回答

0

将您的单元格标识符设置为nil。 这会帮助你。

+0

谢谢你,我试过你的方式和工作。非常感谢你,请告诉我设置单元格标识符为零的背后的概念。 – RameshRajput 2013-02-27 06:15:19

+0

它总是分配新的单元格。 – 2013-03-07 07:01:09

1

我发现很难理解你的疑惑。 但试试这个。 在xib中给出不同的细胞标识符。 并在diff区域中使用diff单元格 问题是第0单元正在重用第2单元格。

+0

我已经将单元格标识设置为零,并且它的工作很好,你们中的一个像朋友一样建议我,但是我仍然需要知道背后的概念。 – RameshRajput 2013-02-27 06:16:01

+0

Ios不会创建所有单元格。只有那些在一次看到的数字。当你滚动出去的单元格在下面重用。你给cellIdentifier一个单元格。当你用相同的标识符创建单元时,Ios会尝试重用单元。它可以节省内存。而不是让cellIdentifier零给每个部分不同的值。并在每个单元格中创建这些名称的单元格。 – Durgaprasad 2013-02-27 06:59:53