区分UITableViewCell上的单击和双击

时间:2015-11-17 13:17:56

标签: ios swift uitableview uigesturerecognizer uitapgesturerecognizer

我在tableViewCell中添加了一个UITapGestureRecogniser,它识别用户是否双击了一个单元格。如果我双击单元格,则会自动调用函数didSelectRowAtIndexPath。我只是希望如果用户对单元格进行双击而不是两者都调用,则会调用gesturerecogniser的func。有人有想法解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

在viewDidLoad函数中:

let aSelector : Selector = “start:”
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1
view.addGestureRecognizer(tapGesture)

let bSelector : Selector = “stop:”
let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)
doubleTapGesture.numberOfTapsRequired = 2
view.addGestureRecognizer(doubleTapGesture)

tapGesture.requireGestureRecognizerToFail(doubleTapGesture)

动作aSelector将在单击时调用,bSelector将在双击时调用。