handle tap gesture with an argument iphone / ipad

when my tap gesture fires I need to send an additional argument along with it but I must be doing something really silly, what am I doing wrong here:

Here is my gesture being created and added:

  • iPhone indoor location based app
  • Why is XCode Organizer console sometimes empty when I connect my iPhone
  • Line artifacts in mobile Safari
  • NSMutableString stringByReplacingOccurrencesOfString Warning
  • isKindOfClass and NSStringFromClass disagree about UIApplicationDelegate
  • Getting the visible rect of an UIScrollView's content
  • UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:itemSKU:)];
    tapGesture.numberOfTapsRequired=1;
    [imageView setUserInteractionEnabled:YES];
    [imageView addGestureRecognizer:tapGesture];
    [tapGesture release];
    
    [self.view addSubview:imageView];
    

    Here is where I handle it:

    -(void) handleTapGesture:(UITapGestureRecognizer *)sender withSKU: (NSString *) aSKU {
            NSLog(@"SKU%@\n", aSKU);
    }
    

    and this won’t run because of the UITapGestureRecognizer init line.

    I need to know something identifiable about what image was clicked.

    Solutions Collect From Internet About “handle tap gesture with an argument iphone / ipad”

    A gesture recognizer will only pass one argument into an action selector: itself. I assume you’re trying to distinguish between taps on various image subviews of a main view? In that case, your best bet is to call -locationInView:, passing the superview, and then calling -hitTest:withEvent: on that view with the resulting CGPoint. In other words, something like this:

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
    ...
    - (void)imageTapped:(UITapGestureRecognizer *)sender
    {
        UIView *theSuperview = self.view; // whatever view contains your image views
        CGPoint touchPointInSuperview = [sender locationInView:theSuperview];
        UIView *touchedView = [theSuperview hitTest:touchPointInSuperview withEvent:nil];
        if([touchedView isKindOfClass:[UIImageView class]])
        {
            // hooray, it's one of your image views! do something with it.
        }
    }