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)")
            }
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读