我以前问过这个问题,现在我会更清楚地告诉你我的项目情况
我添加了表格视图作为子视图和表格视图,分别有 4 个部分和 1,4(动态),3,2 行的部分。在 section=0,textfield is there ,section=2 2 切换按钮,section=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;
}