ios5xcode4.2

How to differ from different images in iPhone programing


I have a view with some images. I want to know which image I selected. If I select an image, it will come to same method if I select another image.

On every image I select the "touchesEnded:" method is executed. Is there away to differ between the images? Any help will be appreciated.


Solution

  • Try to enymerate throught all views:

    - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
    {
    // Enumerate through all the touch objects.
        for (UITouch *touch in touches)
        {
            //Enumerate through all subviews
            for (UIView *subView in [self.view subviews])
            {
                if (CGRectContainsPoint([subView frame], [touch locationInView:self.view]))
                {
                    //Found touched view
                    /*Optional: you can set to each UIImageView tag and check it here
                    switch (subView.tag)
                    {
                        case 1:
                            break;
                        case 2:
                            break;
                        default:
                            break;
                    }
                    */
                }
            }
         }
     }