gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:20:38 25 4
gpt4 key购买 nike

假设表格 View 单元格中有 10 行,如果滑动任何一行,在按下编辑操作字段后变为可编辑,其余行滑动应被禁用。

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

关于ios - 是否可以在 swift 2.2 中禁用除选定行之外的 tableviewCell 行滑动功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38781526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com