6

我试图UITableView通过设置allowsMultipleSelectionDuringEditing为删除我的一些行YES。这一切都运作良好;圆圈显示在左侧。

但是,对于某些单元格,我不希望左侧的圆圈出现。我怎么做?我cell.selectionStyle = UITableViewCellSelectionStyleNone在编辑过程中尝试过,但没有奏效。

有什么提示吗?

4

3 回答 3

3

为了禁止多选中的某些行,您应该使用tableView:shouldIndentWhileEditingRowAtIndexPath:mix with 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;
    }
}
于 2012-10-10T17:40:53.960 回答
2

首先,使用这些设置:

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 是我的私有方法,其中包含有关选择哪一行的逻辑

于 2018-03-30T08:26:24.203 回答
-1

您是否尝试过实现tableView:editingStyleForRowAtIndexPath: UITableViewDelegate' 方法并返回UITableViewCellEditingStyleNone您不想显示删除控件的单元格?

于 2012-07-08T20:15:01.850 回答