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

根据这个代码,如果我想访问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 Solutions collect form web for “如何获得访问子视图的UIView?”

您可以使用视图的标签属性:

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

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

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

  • UIGestureRecognizer阻止子视图处理触摸事件
  • 了解convertPoint:toView:
  • 适当的做法,inheritanceUIView?
  • 自定义长宽比与自动布局
  • 从UIView获取UIViewController?
  • UILabel层cornerRadius负面影响性能
  • iOS viewDidLoad for UIView
  • 如何在iPhone上绘制“语音泡泡”?