【发布时间】:2018-12-14 03:28:07
【问题描述】:
我正在构建一个表格视图,但我似乎无法同时让常规点击和长按工作。
我已将此代码放在我的 viewDidLoad 中:
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
myTableView.addGestureRecognizer(longPress)
这段代码是我的手势识别器:
@objc func handleLongPress(sender: UILongPressGestureRecognizer){
if UILongPressGestureRecognizer.state == UIGestureRecognizer.State.began {
let touchPoint = UILongPressGestureRecognizer.location(in: self.myTableView)
if let indexPath = self.myTableView.indexPathForRowAtPoint(touchPoint) {
print(indexPath.row)
}
}
}
我在 Stack Overflow 上找到了这段代码,但我认为它对于 Swift 4 来说不是最新的,因为我什至无法在构建失败的情况下运行它。
【问题讨论】:
-
if sender.state == .began {和let touchPoint = sender.location(in: self.myTableView)
标签: ios swift uitableview uigesturerecognizer