开发者

Best practice to identify an UIImageView in a NSMutableArray?

开发者 https://www.devze.com 2023-01-11 10:20 出处:网络
I am going to addObject of 8 UIImageView * to a NSMutableArray. Each UIImageView is User Interaction Enabled.

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' i开发者_JAVA技巧n 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?


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];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号