Swift UITableView长按
2018-04-26 本文已影响0人
AppMonkey
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(sender:)))
table.addGestureRecognizer(longPressRecognizer)
@objc func longPressed(sender: UILongPressGestureRecognizer) {
if sender.state == UIGestureRecognizerState.began {
let touchPoint = sender.location(in: self.table)
if let indexPath = table.indexPathForRow(at: touchPoint) {
print("Long pressed row: \(indexPath.row)")
}
}
}