swift - 在看到按钮之前发生滑动操作 - Swift 编码

标签 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])

最佳答案

移动此代码:

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)之前。它需要是您点击按钮时执行的操作,而不是您现在执行的操作。

关于swift - 在看到按钮之前发生滑动操作 - Swift 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52683055/

相关文章:

ios - 从主屏幕中删除导航栏。

swift - 使用什么数据文件可以轻松导入到带有 Swift 的 iOS 应用程序中?

c - 如何编辑和使用包含双引号和转义字符的字符串?

android - 方法 onTouchEvent 未被调用

android - 以编程方式而不是手指使用 ViewPager 滑动图像

ios - Swift 中的 HealthKit 身份验证

快速适配注释

command-line - Zsh:从下划线更改行编辑光标?

vim - 使用命令模式从内部打开(编辑)多个文件

android - setDrawerLockMode 在 android 中不起作用?