Advertisement

Get the view.tag from a UITapGesturerRecognizer tap

Firstly you create a tap gesture recognizer and then add it to the view dot. UIView dot already has the tag assigned.

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(gotoZone:)];
[dot addGestureRecognizer:tapped];

Later, the problem in gotoZone: method is how to identify which UIView dot did the user tap? Here’s how we did it.

Setup a comparison and then cast the tap, associate the UIView with that tap, and voila, the row is the tag of that view.

if ([sender isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tap = (UITapGestureRecognizer *)sender;
UIView *view = tap.view;
row = view.tag;
}