How to give action on click of an image

I am developing an app in which what i want is when a user clicks on an image in an image view

An Action should be fired(like when a button is clicked).

I don't want button image. I just want an image view and action on it.

Kindly help.


According to your comment, if you want to know about image's index then you can do this by tag property of image view. Assign your image view's tag property as per your need and get the tag on Touch event.

For example :

Add UITapGestureRecognizer

ITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self
tap.numberOfTapsRequired = 1;

[self addGestureRecognizer:tap];

[tap release];

Use its delegate method : - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

// called when touch is began or when user touches 
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    UITouch *touch = [touches anyObject]; 

    int indexOfImageView = touch.view.tag;

Hope it helps you...

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
    singleTap.numberOfTapsRequired = 1;
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:singleTap];
    [singleTap release];

    NSLog(@"single Tap on imageview");


Need Your Help

"This game is not recognized by game center." iPhone Development

iphone xcode ios ios4 game-center

There are already a couple of questions on this but I followed their steps to solve it and it doesn't seem to work for me. Here's what I have done:

Background job with status in rails

ruby-on-rails backgroundworker delayed-job

Hey. I would like to upload a file and then parse it. Because parsing can take up to 10min I installed delayed_job plugin and called parsing function through send_later function. I have to mention ...