如何获得访问子视图的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];
您可以使用视图的标签属性:
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]
。