UIImage name

Discussion in 'iOS Programming' started by KardelSharpeye, Jun 11, 2009.

  1. KardelSharpeye macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #1
    Good morning all,

    Let say i have:
    Code:
    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?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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...
     
  3. KardelSharpeye thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #3
    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
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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.
     
  5. KardelSharpeye thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #5
    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..).
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    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.
     
  7. KardelSharpeye thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #7
    ok i think i got it so keep an array of NSString...thanks man!
     

Share This Page