在看到按钮之前发生滑动动作-快速编码

时间:2018-10-06 20:23:57

标签: swift edit swipe viewcontroller swipe-gesture

我有一个编辑按钮,您可以向右轻扫以将其转到另一个ViewController。但是,当我向右滑动时,它立即将我带到ViewController,而不是露出编辑按钮(有时,在将我带到那里之前,我会瞥见到编辑按钮)。有什么办法可以减慢这个速度或解决这个问题?我正在使用Swift。

override func tableView(_ tableView: UITableView,
               leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?

{
    let modifyAction = UIContextualAction(style: .normal, title:  "Update", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        print("Update action ...")
        success(true)

    })
    modifyAction.title = "Edit"
    modifyAction.backgroundColor = .blue

    let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
    let vc : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "FreshReleaseAdd") as UIViewController
    self.present(vc, animated: true, completion: nil)

    return UISwipeActionsConfiguration(actions: [modifyAction])

1 个答案:

答案 0 :(得分:0)

移动此代码:

let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "FreshReleaseAdd") as UIViewController
self.present(vc, animated: true, completion: nil)

...到success(true)之前。点击按钮时,它应该是您要做的,而不是您现在要做的。