我试着去一个UISwitch加起来也只有一个单元格在我的表视图继承人的代码:添加UISwitch只有一个单元格中的TableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FormCell *cell = (FormCell *) [tableView dequeueReusableCellWithIdentifier: @"FormCell"];
if(cell == nil) cell = [[FormCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FormCell"];
if(indexPath.row == 3)
{
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9, 50, 50)];
[mySwitch addTarget: self action: @selector(flip:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:mySwitch];
[[UISwitch appearance] setOnTintColor:[UIColor colorWithRed:163.0/255.0 green:12.0/255.0 blue:17.0/255.0 alpha:1.0]];
}
return cell;
}
其工作,问题是,当我滚动tableview中向上或向下,它重复的UISwitch,但最终还是在表视图的开始...
任何帮助吗?
我们可以得到更多'tableView:heightForRowAtIndexPath'吗? – Larme 2013-03-11 19:43:36
@Larme为了更好的理解而编辑。 – darkman 2013-03-11 20:01:38