我想通过将UITableView
设置为allowsMultipleSelectionDuringEditing
来删除YES
中的某些行。这一切都运作良好;圆圈显示在左侧。
然而,对于某些细胞,我不希望左侧的圆圈出现。我怎么做?我在编辑过程中尝试了cell.selectionStyle = UITableViewCellSelectionStyleNone
但没有用。
任何提示?
答案 0 :(得分:3)
为了禁止多个选择中的某些行,您应该使用与tableView:shouldIndentWhileEditingRowAtIndexPath:
混合的cell.selectionStyle = UITableViewCellSelectionStyleNone
。
以下是我的代码中的示例:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath*)indexPath {
if (indexPath.row < 4) {
return YES;
} else {
return NO;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// (...) configure cell
if (indexPath.row < 4) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
答案 1 :(得分:1)
首先,使用以下设置:
self.tableView.allowsMultipleSelectionDuringEditing = true
self.tableView.setEditing(true, animated: false)
实现下一个委托方法:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return self.shouldAllowSelectionAt(indexPath)
}
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return self.shouldAllowSelectionAt(indexPath)
}
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if self.shouldAllowSelectionAt(indexPath) {
return indexPath
}
return nil
}
shouldAllowSelectionAt是我的私有方法,其中包含有关选择哪一行的逻辑
答案 2 :(得分:-1)
您是否尝试过实施tableView:editingStyleForRowAtIndexPath: UITableViewDelegate
的方法,并为不希望显示删除控件的单元格返回UITableViewCellEditingStyleNone
?