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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:15:17+00:00 2026-05-26T05:15:17+00:00

I want to perform different actions on different image views which are created dynamically

  • 0

I want to perform different actions on different image views which are created dynamically by parsing an XML. but as imageviews are created in a block so the tag i associate it with the views are of no use as they all came the same which is the LAST tag.
Any help will be appreciated… 🙂

Code:-

@class AppDelegate_iPhone,Litofinter,ParsingViewController;

@interface FirstViewController : UIViewController {

    NSMutableArray *array;
    NSString *logoString;
    AppDelegate_iPhone *appDelegate;

    ParsingViewController *obj;

    UIScrollView *scrollView;

    NSMutableArray *idArray;

//  UIImageView *imgView;

}
@property (nonatomic,retain)UIScrollView *scrollView;
//@property (nonatomic,retain)UIImageView *imgView;

-(void)onTapImage;
@end







#import "FirstViewController.h"
#import "AppDelegate_iPhone.h"
#import "Litofinter.h"

#import "ParsingViewController.h"

@implementation FirstViewController

@synthesize scrollView;//,imgView;

-(id)init{
    if(self == [super init]){
        obj = [[ParsingViewController alloc] init];
        array = [[NSArray alloc] initWithArray: obj.LogoMutableArray];
    }
    return self; 
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    int x=20,y=10;
    int a=50,b=105;


    appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,500, 460)];   
    scrollView.contentSize = CGSizeMake(320,800);
    scrollView.showsVerticalScrollIndicator = YES;

    for (Litofinter *lito in appDelegate.logoArray) {

        NSString * urlString = [lito.cLogo stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
        NSURL * imageURL = [NSURL URLWithString:urlString];

        NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
        UIImage * image = [UIImage imageWithData:imageData];

        UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
        [imgView setFrame:CGRectMake(x, y, 140, 90)];
        imgView.userInteractionEnabled = YES;
        imgView.multipleTouchEnabled = YES;
        imgView.backgroundColor = [UIColor blueColor];
        imgView.tag = lito.cId;
        NSLog(@"Tag Id = %@",imgView.tag);
        NSLog(@"Tag Id = %@",lito.cId);

        [scrollView addSubview:imgView];


        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapImage)];
        [imgView addGestureRecognizer:tgr];
        [tgr release];
        //[imgView release];

        UILabel *cName = [[UILabel alloc]initWithFrame:CGRectMake(a, b, 130, 20)];
        cName.text = lito.cName;
        [scrollView addSubview:cName];

        //Do the rest of your operations here, don't forget to release the UIImageView
        x = x + 150;
        a = a + 140;

        if(x >300)
        {
            y = y +140;
            x = 20;
            b = b +150;
            a = 50;
        }

    //  idArray = [[NSMutableArray alloc]init];
    //  [idArray addObject:lito.cId];

    }
    [self.view addSubview:scrollView];


}


-(void)onTapImage
{

    NSLog(@"Tapped Image Id ======================== %@",view.tag);
    //UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message from mAc" message:[NSString stringWithFormat:@"Tag Id : %@",imgView.tag] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
    //[alert show];
}



- (void)dealloc {
    [super dealloc];
    [scrollView release];
}
@end
  • 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-05-26T05:15:17+00:00Added an answer on May 26, 2026 at 5:15 am

    The correct way is to do this.

    - (void)onTapImage:(UITapGestureRecognizer *)recognizer {
    
        NSLog(@"Tapped Image tag: %d", recognizer.view.tag);
    }
    

    Here recognizer.view is the imageView. Don’t forget to add colon (:) to the selector onTapImage in the following line,

    UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapImage:)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to override OnMouseClick and OnMouseDoubleClick and perform different actions depending on which
I have a view where I want to perform different actions on the items
I have 2 submit buttons and want to perform different actions for each submit
I have a text box on a form and want to perform different actions
I want to make this class dynamically perform functions on itself by passing different
I want to perform different action, not delete objects but archive them. When user
I want to know how can I perform VS2008 load test from five different
I want to perform cascade delete for some tables in my database, but I'm
I have a table on which I want to perform some operations every hour.
I have a HTML option element that I want to perform some actions when

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.