仅为UITableView中的某个部分启用编辑模式

Moh*_*iba 5 uitableview ios swift

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

如果我在整个tableView编辑模式下启用其他单元格的编辑selectable,那么我需要仅在特定部分启用编辑模式,以便在其他单元格时selectable,该部分是可编辑的.

我需要设置编辑的原因是出现在deletable单元格旁边的红色方形减去按钮.

摘要:

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

Lio*_*ion 8

你可以实现canEditRowAtIndexPath类似的方法,

OBJ-C

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


if (indexPath.section == 1) {

    return YES;
}

return NO;
}
Run Code Online (Sandbox Code Playgroud)

斯威夫特:

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

    if indexPath.section == 1 {
        return true
    }


    return false
}
Run Code Online (Sandbox Code Playgroud)

要在编辑期间启用选择,您需要设置,

OBJ-C

     self.yourTableView.allowsSelectionDuringEditing = YES;
Run Code Online (Sandbox Code Playgroud)

迅速

     self.yourTableView.allowsSelectionDuringEditing = true
Run Code Online (Sandbox Code Playgroud)