Iphone 编辑时的UITableView每个单元格选择模式

Iphone 编辑时的UITableView每个单元格选择模式,iphone,uitableview,selection,Iphone,Uitableview,Selection,在我的UITableView中,当它进入编辑模式时,我只希望选择几个单元格。我知道UITableView类具有属性allowssectionduringediting,但这适用于整个UITableView。我没有看到任何相关的委托方法可以在每个单元格的基础上设置它 我能想到的最佳解决方案是将编辑过程中的allowselections设置为YES。然后,在didSelectRowAtIndexPath中,如果表格视图正在编辑,则过滤掉所有不需要的选择。另外,在单元格中,将这些单元格选择样式更改为无

在我的
UITableView
中,当它进入编辑模式时,我只希望选择几个单元格。我知道
UITableView
类具有属性
allowssectionduringediting
,但这适用于整个
UITableView
。我没有看到任何相关的委托方法可以在每个单元格的基础上设置它

我能想到的最佳解决方案是将编辑过程中的
allowselections
设置为
YES
。然后,在
didSelectRowAtIndexPath
中,如果表格视图正在编辑,则过滤掉所有不需要的选择。另外,在
单元格中,将这些单元格
选择样式
更改为无

问题是进入编辑模式不会重新加载
UITableViewCells
,因此它们的
selectionStyle
在滚动到屏幕外之前不会更改。因此,在setEditing中,我还必须遍历可见单元格并设置它们的
selectionStyle

这是可行的,但我只是想知道是否有更好/更优雅的解决方案来解决这个问题。我的代码的基本大纲附在附件中。非常感谢您的任何建议!多谢各位

- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

    if (self.editing && ![self _isUtilityRow:indexPath]) return;
    // Otherwise, do the normal thing...
}

- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

    // UITableViewCell* cell = ...

    if (self.editing && ![self _isUtilityRow:indexPath])
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else
    {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    return cell;
}

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];

    if (editing)
    {
        for (UITableViewCell* cell in [self.tableView visibleCells])
        {
            if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
            {
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
        }
    }
    else
    {
        for (UITableViewCell* cell in [self.tableView visibleCells])
        {
            if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
            {
                cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            }
        }
    }
}

我不确定你的应用程序是如何工作的,但也许你可以尝试在数据源定义中使用以下内容:

// Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

进入编辑模式时,使用该功能过滤第一个选择级别,然后进入第二个选择级别

您可以在进入编辑模式时重新加载表格,或者在选中行后立即取消选择,而不是将选择样式设置为“无”。。。