tags:

views:

51

answers:

1

Hello,

I'm using an NSArray of images, and each image has a tag. I want to know how to retrieve these images from the array using their tags.

Any input would be appreciated. Thanks.

+1  A: 
- (UIImage *)imageFromArray:(NSArray *)array withTag:(NSInteger)tag {
  for (UIImage *image in array) {
    if ([image tag] == tag)
      return image;
  }
  return nil;
}

Completely untested, though.

DarkDust
Thanks a lot for your answer I'll try it.
mshaaban
`UIImage` does not have a `tag` property or method. `UIImageView` does. Unfortunately, the question is not specific enough.
falconcreek
The OP didn't say the the image objects were UIImages or UIImageViews. But a subclass of UIImage with an added tag property might work using the above code.
hotpaw2