myImageView = [[UIImageView alloc] initWithImage:[imagearray objectAtIndex:j]];
[myImageView setUserInteractionEnabled:YES];
[myImageView setTag:i];
if (i==0||i==1) {
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.5];
[UIImageView setAnimationRepeatCount:0];
myImageView.center=CGPointMake(42+t, 220+y);
[self.view addSubview:myImageView];
NSLog(@"my imageviw tag %d",myImageView.tag);
[myImageView release];
t=t+10;
y=y+10;
}
-
Perhaps if you described why you want to find the name of the image, you might get an alternative solution to your problem. – Devraj Apr 30 '11 at 06:39
-
Check my answer : [How to get imagename from imageview](http://stackoverflow.com/questions/1740274/uiimageview-how-to-get-the-file-name-of-the-image-assigned/20700384#20700384) – Nishant Tyagi Dec 20 '13 at 09:34
3 Answers
this code will help you out
- (NSString *) getFileName:(UIImageView *)imgView{
NSString *imgName = [imgView image].accessibilityIdentifier;
NSLog(@"%@",imgName);
return imgName;
}
use this as:
NSString *currentImageName = [self getFileName:MyIImageView];

- 3,539
- 1
- 27
- 49
I still dont fully understood your question..If you want to get the image file name from UIImageView object it is not possible..
The reason is that a UIImageView instance does not store an image file. It stores a displays a UIImage instance. When you make an image from a file, you do something like this:
UIImage *picture = [UIImage imageNamed:@"myFile.png"]; Once this is done, there is no longer any reference to the filename. The UIImage instance contains the data, regardless of where it got it. Thus, the UIImageView couldn't possibly know the filename.
Also, even if you could, you would never get filename info from a view. That breaks MVC.
Shamelessly copied from the answer of this thread..Credit to him

- 1
- 1

- 34,169
- 30
- 118
- 167
There is no way to get name if image file from uiimageview. But you can do one thing - when you are initializing the image view with image names you can add that image name in an array and then set that array index to uiimageview object's tag value. Now when you want to get the image file name you can find that using that array, you just need to get the tag value from uiimageview and get the file name of that tag from array.
Hope it will help!

- 22,743
- 12
- 84
- 133