UITableView的allowMultipleSelectionDuringEditing - 不显示某些单元格的编辑圈

时间:2012-07-08 20:10:11

标签: ios uitableview

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

然而,对于某些细胞,我不希望左侧的圆圈出现。我怎么做?我在编辑过程中尝试了cell.selectionStyle = UITableViewCellSelectionStyleNone但没有用。

任何提示?

3 个答案:

答案 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