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 8466619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:23:40+00:00 2026-06-10T15:23:40+00:00

I have this UITableView which is displaying images, downloaded rom a database, as a

  • 0

I have this UITableView which is displaying images, downloaded rom a database, as a matrix: 4 images in each table row.

To be able to select images from the views I’m using a UITapGestureRecognizer. To make each selection unique I’ve been trying to tag each tap recognizer and each imageView. That’s where the problem is…

I’ve put a log within the for-loop that is creating and tagging the imageViews and recognizers and I can see in the output that they pass through all the values. However when I try to get the tag by later pressing an image I always get “3” (the last number in the table row). This makes me think the tags are simlpy overwriting eachother even though I’m creating a new object in each loop. Either that or I’m reading it out the wrong way.

Unrelated parts cut out.

for (NSInteger i = 0; i < 4; i++){

asyncImage = [[AsyncImageView alloc]
                               initWithFrame:frame];

[asyncImage loadImageFromURL:url];
    asyncImage.tag = i; 
    NSLog(@"TAG %d", asyncImage.tag);
    tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
    tapRecognizer.view.tag = i;
    NSLog(@"TapTAG %d", asyncImage.tag);

    [asyncImage addGestureRecognizer:tapRecognizer];
}

And the method:

- (void)handleTap{
NSLog(@"TAP %d", self.tapRecognizer.view.tag);

}

If you think I’m doing it all totally wrong, a light push in the right direction is always welcome!

Thanks in advance, Tom

  • 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-10T15:23:42+00:00Added an answer on June 10, 2026 at 3:23 pm

    The following line has no effect until the gesture recognizer has been added to a view:

    tapRecognizer.view.tag = i;
    

    This is because tapRecognizer‘s view is initially nil. Make the assignment on the last line of your for loop to correct this problem.

    Also your NSLog is always showing the tag of the last recognizer that you have added

    self.tapRecognizer.view.tag // Instance variable
    

    not the one that fired the event. Change handleTap as follows:

    - (void)handleTap:(UITapGestureRecognizer*) tapRecognizer{
        NSLog(@"TAP %d", tapRecognizer.view.tag);
    }
    

    You should also replace the tapRecognizer instance variable with a local variable in the method that adds the recognizer to the view, and add a colon : to your selector name:

    action:@selector(handleTap:)
    //              HERE: ----^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView on a UIViewController. And this table has say 5 visible
I have a UITableView on a view. This UITableView has cells which are made
I have a UITableView which I present in a UIPopoverController . The table view
I have a UITableView which I have assigned sections. When using didSelectRowAtIndex with indexPath.row
I have a simple UITableView with two sections. Each section has a header which
I have created one application in which if i select on particular row in
I have a UITableView which loads through it's navigationController a new viewcontroller. This code
I have a UITableView which downloads its tableviewcells images from a server. I observed
I have a list of answers which I'm displaying in a UITableView, which is
I have a UITableView which is displaying update posts from various social networks. I

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.