views:

116

answers:

2

I am using gesture recognizers:

Initialize in viewDidLoad:

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

This is what longPress looks like:

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

How can I tie this into?

- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

How will didSelectRowAtIndexPath get a reference to gestureRecognizer.minimumPressDuration?

Basically what I'm trying to achieve is:

**If a user clicks on a cell, check to see if the press is 2 seconds.**
+1  A: 

You can try adding the gesturerecognizer to the tableviewcell, instead of the tableview. UITableViewCells derive from UIView, as such they can accept gesture recognizers.

Joshua Weinberg
Can you show me in code?
Sheehan Alam
Steve seems to have done just that.
Joshua Weinberg
+3  A: 

Try adding it to the UITableViewCell instead of the UITableView by providing the tableView:willDisplayCell:forRowAtIndexPath: method like so:

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