I have a series of imageviews that I identify using their tag. I have added a single tap gesture to the images.
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectImage:)]; [tableGridImage addGestureRecognizer:singleTap]; tableGridImage.userInteractionEnabled = YES; [singleTap release];
This manages to call the selectImage selector ok, but passes the gesture as the sender. I need the imageview as the sender so I can get the tag.
Any ideas on how I can get the imageview and it's tag?
Overview. A gesture recognizer decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition.
Adding a Tap Gesture Recognizer to an Image View in Interface Builder. Open Main. storyboard and drag a tap gesture recognizer from the Object Library and drop it onto the image view we added earlier. The tap gesture recognizer appears in the Document Outline on the left.
A UIGestureRecognizer acts as an abstract base class for various sub-classes in the UIKit - commonly known as gesture recognizers. Developers can use existing gesture recognizers to support responses to a set of common gestures, or create additional gesture recognizers.
I figured out how to get the tag, which was the most important part of the question for me. Since the gesture is the sender, I figured out the the view it is attached to is sent along with it:
[(UIGestureRecognizer *)sender view].tag
I am still curious if anyone can tell me how to send an argument through a UITapGestureRecognizer selector.
The only argument you can send through UITapGestureRecognizer selector is the UITapGestureRecognizer itself as following:
Make sure to put ":" after the selector name like you previously did :
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectImage:)];
Then add a parameter to selectImage so you can retrieve the View as following:
-(void) selectImage:(UITapGestureRecognizer *)gestureRecognizer{ //Get the View UIImageView *tableGridImage = (UIImageView*)gestureRecognizer.view; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With