I have added single and double tap gesture recognisers to UITableViewCells. But after scrolling through the table a few times, there becomes an increasingly longer pause between the end of my swipe gesture to scroll the table, and the start of the scrolling animation.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"tableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[cell addGestureRecognizer:singleTap];
UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[cell addGestureRecognizer:doubleTap];
if (tableView == self.searchDisplayController.searchResultsTableView) {
// search results
}
else {
// normal table
}
return cell;
}
SingleTap: and doubleTap: methods
- (void)singleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do single tap
}
}
- (void)doubleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do double tap
}
}
Since the initial scrolling is smooth I tried adding the gesture recognisers into the if (cell == nil)
condition, but then they where never added to the cells.
I also initially had the gestures added to the tableView rather than the individual cells, but this caused issues with the searchDisplayController i.e. tap on the cancel button not recognised.
I'd appriciate any thoughts, thanks.