I have a UITextView subclass that has an NSIndexPath property that is inside a UITableViewCell. When you tap on it, I’d like to be able to call didSelectRowAtIndexPath.
Here’s what I have:
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
[theTextView addGestureRecognizer:singleFingerTap];
singleFingerTap.delegate = self;
....
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
CustomTextView *theTextView = (CustomTextView *)touch.view;
NSLog(@"%@", theTextView.indexPath);
return YES;
}
I see from this question, I may even have to break up my didSelectRowAtIndexPath logic, which is fine. And I already know the index path of the view that was tapped.
What is the proper way to call this tableView method (or what didSelectRowAtIndexPath would do) from within the gesture recognizer method?
I answered a similar question here. Basically when you call:
the tableview doesn’t fire the
tableView:didSelectRowAtIndexPath:on the tableview’s delegate, so in addition you are forced to directly call (And since you wrote the code in the delegate method there’s no problem):Also your passing
nilfor the action is really not how gesture-recognizers where mean to work:Generally you would do something like this:
That basically tells the gesture recognizer to call the
tapRecognized:method when it receives a tap. So basically to wrap it all up (I’m assuming this is in aUITableViewControlleror an object with a property namedtableViewasUITableViewControllers have by default).