How do I reference an instance of a class using its tag?

Posted by Matt Winters on Stack Overflow See other posts from Stack Overflow or by Matt Winters
Published on 2010-05-02T14:30:44Z Indexed on 2010/05/02 14:37 UTC
Read the original article Hit count: 187

Filed under:
|

I have several instances of a UIControl class Foo being instantiated, one instance corresponding to each cell in a UITableView. The Class has:

BOOL selected;
UIImageView *imageView;
UIImage *imageOne;
UIImage *imageTwo;

I've assigned each instance a tag:

foo.tag = indexPath.row;

I would now like to reference the UIImageView.image for a (or several) specific instance(s) by its tag to switch it to the other image.

In my search I've seen things like classes being assigned tags using initWithTag (I assume they're assigning tags)...

SomeClass *someClass = [[SomeClass alloc]initWithTag:1 ...

[someArray addObject: [[SomeClass alloc]initWithTag:2 ...
[someArray addObject: [[SomeClass alloc]initWithTag:3 ... 

...but I haven't seen how they are later referenced by that tag.

I have seen a reference to getChildByTag which had promise, but I can't find it in the documentation or examples (maybe not iphone).

Does anyone know how reference the imageView.image within an instance using its tag?

Thanks

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk