33

根据此代码,如果我想访问 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];
4

2 回答 2

84

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];
于 2010-03-17T09:13:09.207 回答
10

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

于 2010-03-21T17:06:34.497 回答