简体   繁体   English

如何使用UISwipeActionsConfiguration设置删除单元格的延迟?

[英]How to set the delay in deleting cell with UISwipeActionsConfiguration?

I'm creating a task list. 我正在创建一个任务列表。 You can mark task and done by swiping the cell and clicking the swipe button. 您可以通过滑动单元格并单击滑动按钮来标记任务和完成。 The .destructive style makes the cell disappear immediately which doesn't look good here. .destructive样式使单元格立即消失,在这里看起来不太好。 I'd like to make it a bit slower (could be fading first and than disappearing). 我想让它慢一点(可以先消失然后消失)。

I'm learning Swift and have no idea how to do it and didn't find any tip on the internet. 我正在学习Swift,不知道该怎么做,并且在互联网上找不到任何提示。 Could anyone help me? 有人可以帮我吗?

Here's my func: 这是我的功能:

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let markAsDone = UIContextualAction(style: .destructive, title: "DONE") { (doneAction, view, isSuccess) in
            print("User marked task as done")
            isSuccess(true)
        }
        markAsDone.backgroundColor = UIColor.lightGray
        return UISwipeActionsConfiguration(actions: [markAsDone])
    }

You can try something like this, 你可以尝试这样

tableView.beginUpdates()
tableView.deleteRows(at: indexPath, with: .fade) // Use your desired indexPath
tableView.endUpdates()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM