问题描述
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 (将#修改为@)