Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9053263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:22:57+00:00 2026-06-16T13:22:57+00:00

This question had been asked in some form before, but I could not find

  • 0

This question had been asked in some form before, but I could not find an answer that would be applicable to my situation.

In a nutshell: I am building a gallery module for my application. It consist of several sections, with a number of thumbnail images in each section. The basic principle is that an image viewer module gets initiated and presented modally based on what section the user is in and which thumbnail he or she taps on. Seems very simple; all I need is to pass two int variables (one for the section and one for the image) upon initialization of the image viewer, and everything is hunky-dory.

The problem is that UITapGestureRecognizer cannot call a method directly. It uses selectors, through which I am unable to pass an argument, let alone two. What I am looking for is something like this:

[thumbnail004 setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap004 = [[UITapGestureRecognizer alloc] 
                       initWithTarget:self
                       action:@selector(imageTappedWithSectionNumber:6
                                                      andImageNumber:4)];
[thumbnail004 addGestureRecognizer:tap004];

Is there a way to call a method directly with arguments when using UITapGestureRecognizer?

If not, one obvious way to solve this problem would be to create separate methods for each image tap, like:

- (void) image1_1Tapped { 
  // View initialization by passing 1 and 1
  }
- (void) image1_2Tapped { 
  // View initialization by passing 1 and 2
  }
And so on...

This would be possible because the image library is not dynamic, however, it would be the ugliest code in the world, and I would like to avoid it at any cost.

There must be a way to do this with a clean and elegant code…!

For further reference:
1. I do not use IB; I do everything programmatically.
2. Passing one argument is not enough; I really need to pass two.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:22:58+00:00Added an answer on June 16, 2026 at 1:22 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may have been asked before, but I had trouble finding an answer,
I know that this question had been asked many times, but every answer seems
I know that this question had already been asked a couple of times before,
I figured this answer had been asked before, so I searched, but I couldn't
I know this question has been asked before but for some reason I am
I know, variations of this question had been asked before. But my case may
for sure this question has been asked before, but I couldn't find any thread
This question has been asked before but 1) the user never accepted an answer
I know this question had been asked a hundred times, but I have difficulties
So, if this question has been asked before, I'm sorry. I'm not exactly sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.