views:

45

answers:

1

I am going to addObject of 8 UIImageView * to a NSMutableArray. Each UIImageView is User Interaction Enabled.

When a user touches one of the UIImageViews, what is the best way to recall the index position of the selected UIImageView' in theNSMutableArray`?

I can imagine:

  • sub-class UIImageView and add a NSUInteger index attribute
  • traverse the NSMutableArray and compare each UIImageView * pointer

Is there an better alternative?

+2  A: 

setting a tag would be the easiest way: [myImageView setTag:anIdentifier]; you could set the tag number as the same as the index in the array.

Or you could search for your imageView object in the array every time you need it: [myarray indexOfObject:myImageView];

nacho4d