如何获取滑动手势的位置/索引路径?

问题描述

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.register(UITableViewCell.self,forCellReuseIdentifier: "SavedExercise")
    
    let swipeRight = UISwipeGestureRecognizer(target: self,action: #selector(respondToSwipeGesture))
    self.view.addGestureRecognizer(swipeRight)
}

@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
    currentIndex = self.tableView.indexPathForSelectedRow
    let ac = UIAlertController(title: "Want to delete from saved exercises?",message: nil,preferredStyle: .actionSheet)
    ac.addAction(UIAlertAction(title: "Yes",style: .default,handler: swipedRight))
    ac.addAction(UIAlertAction(title: "No",style: .cancel))

}

@objc func swipedRight(action: UIAlertAction) {
    if let unwrapped = currentIndex {
        savedExercises.remove(at: unwrapped.row)
        self.tableView.reloadData()
    } else {
        print("right swipe messed up somewhere")
    }
}

看了很多答案,但都在 obj-c 中,而不是 Swift。当前的 indexPathForSelectedRow 变量似乎不起作用。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...