如何获取UIView的访问子视图?

时间:2010-03-17 09:10:18

标签: iphone uiview subview

根据此代码,如果我想访问imageView1和imageView2 我怎样才能访问它? 请给我看一些例子

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

2 个答案:

答案 0 :(得分:84)

您可以使用view的标记属性:

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

稍后使用-viewWithTag:方法获取子视图:

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

答案 1 :(得分:10)

我相信你可以通过调用
来访问superview中的所有子视图 [cell.accessoryView subviews]