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.
Asked
Active
Viewed 2,130 times
1
-
Are you loading it from an array? – Adeel Ur Rehman Dec 11 '14 at 12:02
-
yes but I don't want to use array. because it is very basic solution. – Dec 11 '14 at 12:04
-
I want to something like When click on image it will give me name of image also. @AdeelUrRehman – Dec 11 '14 at 12:06
-
You have to create your own ImageView and add a property that store the name of the image and also set the image to the image view. – Adeel Ur Rehman Dec 11 '14 at 12:07
-
Use tags to identify images. I don't think so there is a way to get image names from `UIImage` object. – Kampai Dec 11 '14 at 12:08
-
What do you mean by `image name`? – user623396 Dec 11 '14 at 12:12
-
@AdeelUrRehman I think it's bad practice to subclass uiimageview. can we use gesturerecognizer for that? – Dec 11 '14 at 12:13
-
why you r not using custom UIButton instead of UIImageView ? – sanjeet Dec 11 '14 at 12:15
-
@stack you want to get the name of the image which you cannot get using the gesture recognizer. In your question you mentioned **I want to know name of that image** – Adeel Ur Rehman Dec 11 '14 at 12:19
-
possible duplicate http://stackoverflow.com/questions/1740274/uiimageview-how-to-get-the-file-name-of-the-image-assigned – sanjeet Dec 11 '14 at 12:19
-
thanks for quick reply all. I think subclassing uiimageview is good solution for that. – Dec 11 '14 at 12:22
-
why do you need to know the _image's name_? – holex Dec 11 '14 at 13:47
-
@holex because I have thumbnail image in my UIImageView and I want to download original image from server after click on thumbnail image. – Dec 11 '14 at 14:18
2 Answers
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