是否可以禁用 swift 2.2 中选定行以外的 tableviewCell 行滑动功能?

Is it Possible to disable tableviewCell row swipe features except the selected row in swift 2.2?

假设 table 视图单元格中有 10 行,如果滑动任何一行,在按下编辑操作字段后变成 editable 并且剩余的行滑动应该被禁用。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{

     /*to perform edit action on row*/
    let edit = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit"){(UITableViewRowAction,NSIndexPath) -> Void in


    let cell:SuppliersCutomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! SuppliersCutomTableViewCell
        print("indexPath",indexPath)
/*making Field Editable method*/
     cell.textFieldedit()

    }

    edit.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);

    return [edit]
}

您可以为此使用 UITableViewDataSourcecanEditRowAtIndexPath 方法,首先像这样在 Bool 实例上声明并在 UITableViewDataSource 方法中使用它。

var allowEdit: Bool = true

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

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{

    /*to perform edit action on row*/
    let edit = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit"){(UITableViewRowAction,NSIndexPath) -> Void in


        let cell:SuppliersCutomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! SuppliersCutomTableViewCell
        print("indexPath",indexPath)
        /*making Field Editable method*/
        cell.textFieldedit()
        self.allowEdit = false
    }

    edit.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);

    return [edit]
}

注意:当您对该单元格进行编辑时,不要忘记将 self.allowEdit 设置为 true

根据需要使用UITableView和returnBool的tableView:canEditRowAtIndexPath:方法

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    var canEdit = selectedCell == indexPath.row ? true : false
return canEdit

}