简体   繁体   English

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

[英]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? 根据此代码,如果我要访问imageView1和imageView2,我该如何访问它? please show me some example 请给我看一些例子

example cell.accessoryView.subviews ? 示例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];

You can use view's tag property: 您可以使用view的tag属性:

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: 然后使用-viewWithTag:方法获取子视图:

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

I believe u can access all subviews in superview simply by calling 我相信您只需调用即可访问超级视图中的所有子视图
[cell.accessoryView subviews] . [cell.accessoryView subviews]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM