我正在使用手势识别器:

viewDidLoad初始化:

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
 [self.view addGestureRecognizer:longPressRecognizer];

这是longPress的样子:
- (void)longPress:(UILongPressGestureRecognizer*)gestureRecognizer {
 if (gestureRecognizer.minimumPressDuration == 2.0) {
  NSLog(@"Pressed for 2 seconds!");
 }
}

我该如何搭配呢?
- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

didSelectRowAtIndexPath如何获得对gestureRecognizer.minimumPressDuration的引用?

基本上我想要达到的是:
**If a user clicks on a cell, check to see if the press is 2 seconds.**

最佳答案

通过提供tableView:willDisplayCell:forRowAtIndexPath:方法,尝试将其添加到UITableViewCell而不是UITableView中,如下所示:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     [cell addGestureRecognizer:longPressRecognizer];
}

10-08 17:00