[英]How to dismiss swipe action context menu on cancel
I've added a swipe to delete functionality with the use of我添加了一个滑动来删除功能,使用
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)
-> UISwipeActionsConfiguration?
I'm calling an alert with dismiss/confirm actions.我正在调用带有关闭/确认操作的警报。 Once dismissed I want to dismiss the swipe action menu.一旦被解雇,我想关闭滑动操作菜单。
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteClosure:UIContextualAction.Handler = {
(action:UIContextualAction,
view:UIView,
completionHandler:(Bool) -> Void) in
let alert = self.confirmDeletion({ _ in
let row = indexPath.row;
let removed = self.logList.remove(at: row);
self.deleteLogEntry(removed);
//
tableView.reloadData();
//
}, declineBlock: {_ in
tableView.reloadData();// this hides it but w/o animation
});
DispatchQueue.main.async {
self.present(alert, animated: true, completion: nil);
}
}
let deleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: deleteClosure);
return UISwipeActionsConfiguration(actions: [deleteAction]);
}
So far I've found that reloading table data will close the trailing swipe menu but w/o animation which looks odd.到目前为止,我发现重新加载表格数据会关闭尾部滑动菜单,但没有动画,这看起来很奇怪。 Is there a way to tell it to dismiss with an animation?有没有办法告诉它用动画解散?
** Note about duplicate ** Marked as duplicate to the question that refers to dismiss not working as expected AFTER row was deleted, it is not the case here. ** 关于重复的注意事项 ** 标记为重复的问题是指在删除行后解雇未按预期工作,这里不是这种情况。 I want to dismiss trailing swipe when user cancels deleting and row is NOT removed.当用户取消删除并且行未被删除时,我想关闭尾随滑动。
What I've already tried:我已经尝试过的:
tableView.setEditing(false, animated: true);
- no visible difference - 无明显差异tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.automatic);
- row was moved right with animation but the button was overlapping - 行随着动画向右移动,但按钮重叠tableView.resignFirstResponder();
- no visible difference (I had to try) - 没有明显的区别(我不得不尝试)tableView.reloadTable()
- swipe menu IS dismissed but w/o animation effect tableView.reloadTable()
- 滑动菜单被关闭但没有动画效果You need to call the completionHandler with the result to dismiss the swipe action.您需要使用结果调用 completionHandler 以取消滑动操作。 Here is the help on the UIContextualActionHandler;这是 UIContextualActionHandler 的帮助;
// call the completionHandler to reset the context to its normal state (e.g. when swiping, resets to unswiped state)
// pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion
typedef void (^UIContextualActionHandler)(UIContextualAction *action, __kindof UIView *sourceView, void(^completionHandler)(BOOL actionPerformed));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.