如何隐藏 UITableView 中某些单元格的 multi-select edit gui?

How do I hide the multi-select edit gui for certain cells in UITableView?

我正在使用 UITableView,将编辑设置为 true,并在界面生成器中使用这些选项:

这显示了一个不错的选择 UI 我可以修改其样式和我可以对事件做出反应:

我想关闭它,但仅限于某些单元格。我见过 this 和许多类似的问题,但它们指的是 UITableView 中不同类型的选择。 UITableViewCellSelectionStyle.NonewillSelectRowAtIndexPath 不允许我阻止此类选择。

您是否尝试实施

func tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

在你的委托中?

我相信它会让你获得你想要达到的结果。

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if(indexPath.row == index of cell you don't want the selection for)
{
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

cell.textLabel.text = [a objectAtIndex:indexPath.row];
return cell;
}

例如:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *a = @[@"md",@"dh",@"kkd",@"dkkls"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if(indexPath.row == 2)
{
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

cell.textLabel.text = [a objectAtIndex:indexPath.row];
return cell;
}

它不会在您的表格视图中显示 "kkd" 的选择