1

I have a UIScrollview. In the UIScrollview there are 4 UIImageViews with images. When I click on any UIImageview I want to know the name of that image.

Julian E.
  • 4,687
  • 6
  • 32
  • 49

2 Answers2

4

UIImageView just keeps the pointer to the place the UIImage is stored inside the memory, so it's not possible with UIImageView. You would need to create a subclass of UIImageView with a NSString variable which stores the value to access it later. Something like this:

#import <UIKit/UIKit.h>

@interface MyImageView : UIImageView

@property (strong, nonatomic) NSString *imageName;

@end
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
1

The image names are not stored in UIImage objects so you have to keep them somewhere else for lookup. To detect touches in image views you either have to subclass them and add code for touch detection, add tap recognizers or replace them with buttons.

Alexander
  • 8,117
  • 1
  • 35
  • 46
  • I âm using tap Recognizers. how can get name of image using recognisers please? –  Dec 11 '14 at 12:09
  • For example, give each image view a tag that corresponds to the index of the image name in the array and use it to retrieve the name. – Alexander Dec 11 '14 at 12:11