首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在取消拖刷操作时添加操作(Swift 5)

如何在取消拖刷操作时添加操作(Swift 5)
EN

Stack Overflow用户
提问于 2020-10-09 16:41:19
回答 2查看 288关注 0票数 1

在我的项目中,我使用了trailingSwipeActionsConfigurationForRowAt函数。我也会在需要的时候使用selectRow函数。如果我的单元格被选中,我使用了swipe,然后我取消了它(从左向右滑动),我的单元格不会再次被选中。我可以在哪里修复它(再次使用selectRow )?

代码语言:javascript
复制
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .destructive, title: "") { [weak self] (contextualAction, view, boolValue) in
            guard let self = self else { return }
            self.deleteRow(at: indexPath)
        }
        deleteAction.image = UIImage(systemName: "trash")
        
        let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])
        
        return swipeActions
    }
EN

回答 2

Stack Overflow用户

发布于 2021-04-29 06:50:11

您可以使用:

代码语言:javascript
复制
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
  //Get the cell's indexPath (be aware of the optional argument and threat it the way you want)
  let cell = tableView.cellForRow(at: indexPath!)
  //Use the cell to the changes you need
}

如果你想获得一个平滑的效果,你也可以使用动画。

票数 1
EN

Stack Overflow用户

发布于 2020-10-09 18:14:54

您不会调用完成处理程序。根据API文档,需要调用完成处理程序来指示操作是否成功。

代码语言:javascript
复制
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
            let deleteAction = UIContextualAction(style: .destructive, title: "") { _, _, complete in
                // remove object from your array..
                self.arrayName.remove(at: indexPath.row)
                //reload the table to avoid index out of bounds crash..
                self.tableView.deleteRows(at: [indexPath], with: .automatic)
                complete(true)
            }
            
            deleteAction.image = UIImage(named: "trash")
            let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
            configuration.performsFirstActionWithFullSwipe = true
            return configuration
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64276660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档