Sef*_*efu 0 xcode uitableview ios swift
我有一个单元格删除句柄功能,提醒确认对话框,如果用户按"好",它将继续并删除单元格.否则,我希望它以编程方式隐藏删除按钮.我设置了以下函数来处理在UITableViewDelegate中删除UITableView单元格:
// delete a cell
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if(editingStyle == .Delete) {
var deleteAlert = UIAlertController(
title: "Delete?",
message: "All data will be permanently deleted.",
preferredStyle: UIAlertControllerStyle.Alert)
deleteAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: {
(action: UIAlertAction!) in
// delete logic here:
self.deleteDataForCell(indexPath.row)
self.myTable.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
println("Delete successful")
}))
deleteAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: {
(action: UIAlertAction!) in
println("Delete cancelled")
// TODO - now hide the delete button with animation
}))
presentViewController(deleteAlert, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
"TODO"部分是我不知道如何强制表以编程方式隐藏删除按钮的地方.现在,删除按钮将保持在视图中,直到用户点击屏幕上的其他位置.我可以打电话,myTable.reloadData()但这不是动画.
小智 7
找到一个使用此解决方案:
self.tableView.setEditing(false, animated: true)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1141 次 |
| 最近记录: |