[英]How to dismiss swipe action context menu on cancel
我添加了一個滑動來刪除功能,使用
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)
-> UISwipeActionsConfiguration?
我正在調用帶有關閉/確認操作的警報。 一旦被解雇,我想關閉滑動操作菜單。
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]);
}
到目前為止,我發現重新加載表格數據會關閉尾部滑動菜單,但沒有動畫,這看起來很奇怪。 有沒有辦法告訴它用動畫解散?
** 關於重復的注意事項 ** 標記為重復的問題是指在刪除行后解雇未按預期工作,這里不是這種情況。 當用戶取消刪除並且行未被刪除時,我想關閉尾隨滑動。
我已經嘗試過的:
tableView.setEditing(false, animated: true);
- 無明顯差異tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.automatic);
- 行隨着動畫向右移動,但按鈕重疊tableView.resignFirstResponder();
- 沒有明顯的區別(我不得不嘗試)tableView.reloadTable()
- 滑動菜單被關閉但沒有動畫效果您需要使用結果調用 completionHandler 以取消滑動操作。 這是 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.