- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
if (self.tableView.isEditing) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleMultiSelect;
}
-(IBAction) switchEditing {
[self.tableView setEditing:![self.tableView isEditing]];
[self.tableView reloadData]; // force reload to reset selection style
}
ありがとう!これはほぼ完璧に動作します!選択したセルに表示されるターコイズのハイライトを削除することが可能かどうかを知っていますか? –
willSelectRowAtIndexPathを呼び出した後、ターコイズのハイライト表示(UITableViewCellSelectedBackground)が挿入されるため不可能と思われます。 didSelectRowAtIndexPathで削除すると、セルがタッチされている間も表示されます。 – Felix
UITableViewCellをサブクラス化し、setSelected:animatedをオーバーライドすることができます。 – Felix