RAGOpoR
RAGOpoR

Reputation: 8168

how to get access subview of UIView?

according to this code if i want to access imageView1 and imageView2 how can i access to it? please show me some example

example cell.accessoryView.subviews ?

UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease];
UIImageView *imageView2 = [[[UIImageView alloc] init] autorelease];
imageView2.alpha = 0;
[cell.accessoryView addSubview:imageView1];
[cell.accessoryView addSubview:imageView2];

Upvotes: 33

Views: 55271

Answers (2)

Tankista
Tankista

Reputation: 1770

I believe u can access all subviews in superview simply by calling
[cell.accessoryView subviews].

Upvotes: 10

Vladimir
Vladimir

Reputation: 170829

You can use view's tag property:

UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease];
imageView1.tag = 100;
UIImageView *imageView2 = [[[UIImageView alloc] init] autorelease];
imageView2.tag = 200;
imageView2.alpha = 0;
[cell.accessoryView addSubview:imageView1];
[cell.accessoryView addSubview:imageView2];

And later get subview using -viewWithTag: method:

UIImageView *getImageView1 = (UIImageView*)[cell.accessoryView viewWithTag:100];

Upvotes: 83

Related Questions