tags:

views:

1036

answers:

2

Hi,

I have four imageview in sequence on a screen setting with custom background images. When user touches an imageview (for ex: user touches second imageview), can i get touch notification with which imageview is touched? I have array of imageview already and placed, and i have to implement touch event and under that identify which imageview is selected.

I want help from some one who can have suggestions to develop this, please suggest me?

thanks.

+1  A: 

you can use custom buttons instead of UIImages. so it will be easy to find which of them was pressed.

Morion
He is talking about UIImageViews, not UIImages. There is IMHO no need to use buttons but simply catch the touch-event inside your UIImageView and propagate it up to the superview.
Till
I use buttons with images a lot for this kind of interface. Buttons have the advantage of having all the touch handling code written for you. You just register your controller and one of its methods as the button's action target for a touch up and you're done. No subclassing, no coding in the button itself at all.
TechZen
A: 

Using UIButtons as replacements for your UIImageViews is a great idea that Morion mentioned as you can just drag a connection from each button to an outlet in your view controller and handle the action. You can set the background image on the buttons as you are doing currently with the UIImageViews. Set your button type to custom and you'll be good to go.

If, however, you are set on using UIImageView, you will have to subclass UIImageView and override the touch methods you want to intercept. For example:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Call super to make sure you don't lose any functionality
    [super touchesBegan:touches withEvent:event];

    // Perform the actions you want to perform with the tap.
}
Matt Long
Thanks a lot. I already made as UIImageViews. When i click on a imageview, notification comes to 'touchesBegan' as you have rightly suggested. But how would i know which imageview has selected? I should know whether imgView1 or imgView2 or imgView3 or imgView4 is being touched during this time?
Ok. I removed imageviews and used Buttons itself. It is working as expected.