2010-03-17 28 views
33

theo mã này nếu tôi muốn truy cập imageView1 và imageView2 làm cách nào tôi có thể truy cập vào nó? vui lòng chỉ cho tôi một số ví dụcách truy cập chế độ xem phụ của UIView?

ví dụ cell.accessoryXem.subviews?

UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease]; 
UIImageView *imageView2 = [[[UIImageView alloc] init] autorelease]; 
imageView2.alpha = 0; 
[cell.accessoryView addSubview:imageView1]; 
[cell.accessoryView addSubview:imageView2]; 

Trả lời

84

Bạn có thể sử dụng tài sản thẻ điểm của:

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

Và sau đó có được subview sử dụng -viewWithTag: phương pháp:

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

Tôi tin rằng u có thể truy cập vào tất cả các subviews trong SuperView chỉ đơn giản bằng cách gọi
[cell.accessoryView subviews].

Các vấn đề liên quan