仅针对UITableView中的一部分启用编辑模式 [英] Enable editing mode just for a section in UITableView

查看:70
本文介绍了仅针对UITableView中的一部分启用编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableView ,其中有一个可编辑的部分.

I have a tableView in which there is a section that is editable.

如果我允许在整个 tableView 上进行编辑,则在编辑模式下的其他单元格不是 selectable ,因此我只需要在特定部分上启用编辑模式,因此当其他单元格是 selectable 时,该部分是可编辑的.

If I enable editing on the entire tableView, other cells while in editing mode are not selectable, so I need to enable the editing mode only on a specific section so that while other cells are selectable, the section is editable.

我需要进行编辑的原因是出现在 deletable 单元格旁边的那些红色方形减号按钮.

The reason that I need to set editing is those red square minus buttons that appear next to deletable cells.

摘要:

我需要在单元格旁边的红色减号按钮,所以我需要将编辑设置为true,但是如果这样做,其他单元格将不是 selectable ,因此我需要将编辑设置为对于特定部分为true,或者在不使用编辑模式的情况下添加那些红色的减号按钮.

I need those red minus buttons next to cells, so I need to set editing as true, but if I do so, other cells won't be selectable thus I need to either set editing as true for a specific section, or add those red minus buttons without the editing mode.

推荐答案

您可以实现 canEditRowAtIndexPath 方法,

Obj-C

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


if (indexPath.section == 1) {

    return YES;
}

return NO;
}

快捷键:

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

    if indexPath.section == 1 {
        return true
    }


    return false
}

要在编辑过程中启用选择,您需要进行设置,

To enable selection during editing you need to set,

Obj-C

     self.yourTableView.allowsSelectionDuringEditing = YES;

快速

     self.yourTableView.allowsSelectionDuringEditing = true

这篇关于仅针对UITableView中的一部分启用编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆