我正在尝试创建一种选择单元格的方法,以便我可以对其进行编辑。使用当前代码,上升的单元格始终是下一个单元格。而且我的最后一个单元格tableView
无法选择。
@objc func handleLongPress(_ longPressGestureRecognizer: UILongPressGestureRecognizer) {
if longPressGestureRecognizer.state == UIGestureRecognizerState.began {
let touchPoint = longPressGestureRecognizer.location( in : self.view)
if let indexPath = tableView.indexPathForRow(at: touchPoint) {
let context = (UIApplication.shared.delegate as!AppDelegate).persistentContainer.viewContext
let cell_selected = classements[indexPath.row]
nomAjouterOutlet.text = cell_selected.nom
pointAjouterOutlet.text = "\(cell_selected.point)"
classeAjouterOutlet.text = cell_selected.classe!
// Context CoreData
context.delete(cell_selected)
(UIApplication.shared.delegate as!AppDelegate).saveContext()
do {
classements =
try context.fetch(Tournoi.fetchRequest())
} catch {
print("Fetching Failed")
}
classementTableView.reloadData()
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
let longPressGesture: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(ClassementViewController.handleLongPress(_: )))
longPressGesture.minimumPressDuration = 1.0
longPressGesture.delegate = self
self.tableView.addGestureRecognizer(longPressGesture)
}