Kan*_*rus 5 editing uitableview ios swift
我想知道是否有选项可以关闭表格视图中的编辑菜单(如屏幕截图所示),当我们向右滑动时会看到该选项。我希望菜单在我选择一个选项后立即关闭,在我的情况下,即使我选择了任何一个选项,它也不会关闭。只有当我选择屏幕上的任何地方时它才会关闭。
下面是我使用的代码
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
let update = UITableViewRowAction(style: .Normal, title: "Update") { action, index in
print("update")
}
let delete = UITableViewRowAction(style: .Default, title: "Delete") { action, index in
print("Delete")
}
return [delete, update]
}
Run Code Online (Sandbox Code Playgroud)
您只需重新加载特定的单元格即可关闭该选项。
为此,您可以使用以下代码可以解决您的问题。
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
Run Code Online (Sandbox Code Playgroud)
您也可以使用
self.tableView.setEditing(false, animated: true)
Run Code Online (Sandbox Code Playgroud)
快乐编码。
归档时间: |
|
查看次数: |
10410 次 |
最近记录: |