PDA

View Full Version : UIImage name




KardelSharpeye
Jun 11, 2009, 11:19 AM
Good morning all,

Let say i have:

NSArray imageNames = [NSArray arrayWithObjects:[UIImage imageNamed:"image1.png"], [UIImage imageNamed:"image2.png"]];

NSMutableArray imageViews = [[NSMutableArray alloc] init];

for( i=0; i < [imageNames count]; i++) {
UIImageView *tempImage = [[UIImageView alloc] initWithImage:[imageNames objectAtIndex:i]];

[imageViews addObject:tempImage];
}



is there anyway i can track down which: image1.png or image2.png, i just clicked?



robbieduncan
Jun 11, 2009, 11:21 AM
Keep an array of the UIImageViews (in the same order as the UIImages) and check which UIImageView the message comes from. UIImages don't keep track of which file (or URL) they come from. I suppose because you can create images from raw data...

KardelSharpeye
Jun 11, 2009, 11:23 AM
i dont understand. i do have an array of UIImageViews its NSMutableArray and i dont see any method in the API to compare the names

robbieduncan
Jun 11, 2009, 11:25 AM
i dont understand. i do have an array of UIImageViews its NSMutableArray

So you do. So you just need to check which one is sending the message. Each touch event has a view property which tells you which view sent the message. Just iterate over the array of UIImageViews checking if they are equal to this property. That will tell you the index if the touched image.

KardelSharpeye
Jun 11, 2009, 11:32 AM
yeah i know i can check if the object touched is contained in the array but after finding out which index or object it is, i was just wondering if i can find out its name(image1.png, image2.png, etc..).

robbieduncan
Jun 11, 2009, 11:38 AM
Did you read my post? UIImages don't track that. You need to use the index from the UIImageView array to lookup the name in an array of your own with the file names.

KardelSharpeye
Jun 11, 2009, 11:39 AM
ok i think i got it so keep an array of NSString...thanks man!