私は11以上の行を持っています。最初のセルでのみUISwitchを作成する必要があります。任意の行をクリックするとUIスイッチが複製されます。1つのテーブルビューセルでUISwitchを作成する - UISwitchが重複する
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EN_MoreTableViewCell];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:EN_MoreTableViewCell];
cell.backgroundColor = [UIColor clearColor];
}
cell.textLabel.text = languageObject.name;
[cell.textLabel setFont:font];
if (indexPath.row == 0 && [languageObject.name isEqual: @"All Languages"]) {
if (!mySwitch) {
mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(_languageListTableView.frame.size.width - 60, 0, 40, 40)];
[cell.contentView addSubview:mySwitch];
}
cell.accessoryType = UITableViewCellAccessoryNone;
}
else { //other cell code//
}
助けてください。
コードをフォーマットしてください。 – shallowThought
最も便利な方法は、Interface Builderで2つの別個のテーブルビューセルを作成することです。 – vadian