假设在表格视图单元格中有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]
}
您可以为此使用canEditRowAtIndexPath
方法,首先UITableViewDataSource
在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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句