iOS:如何在确认对话框后设置隐藏在UITableCell“删除”菜单中的动画?
我有一个单元格删除句柄功能,可以提醒确认对话框,如果用户按下OK,它将继续删除单元格。否则,我希望它以编程方式隐藏delete按钮。我设置了以下函数来处理在UITableViewDelegate中删除UITableView单元格:iOS:如何在确认对话框后设置隐藏在UITableCell“删除”菜单中的动画?,ios,xcode,uitableview,swift,Ios,Xcode,Uitableview,Swift,我有一个单元格删除句柄功能,可以提醒确认对话框,如果用户按下OK,它将继续删除单元格。否则,我希望它以编程方式隐藏delete按钮。我设置了以下函数来处理在UITableViewDelegate中删除UITableView单元格: // delete a cell func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPat
// 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)
}
}
TODO部分是我不知道如何强制表格以编程方式隐藏delete按钮的部分。现在,删除按钮将保持在视图中,直到用户点击屏幕上的其他位置。我可以调用myTable.reloadData,但它没有设置动画。找到了使用以下方法的解决方案:
self.tableView.setEditing(false, animated: true)
您尝试过使用RowAnimation:UITableViewRowAnimation重新加载RowSatindExpaths\uInExpaths:[AnyObject]吗?我刚刚尝试过,但效果并不完全符合我的期望。它将按此处所述设置整个单元格的动画:但不会撤消动画中的幻灯片。没有一个选项允许你在屏幕上点击其他地方时获得相同的默认动画。我更详细地研究了它。当单元格显示“删除确认”按钮时,它会向单元格添加手势识别器。当用户点击按钮外部时,该识别器会调用单元格上的私有方法,从而使其返回动画并删除删除确认按钮。所以你可能不得不面对一个混乱的工作环境。