Swift UITableView长按

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)")
            }
        }
    }

推荐阅读更多精彩内容