tags:

views:

25

answers:

1

There are three UIView *view1,view2 , view3; Now, view1 have to be shown at both of view2 and view3 at the same time. But as usually, one view could be insert at only one view... Is there any method to insert one view at two different view ?

+1  A: 

No. A UIView instance can only be a subview of exactly 1 other UIView instance.

You need to create 2 UIView instances. To avoid code duplication, you could subclass UIView:

@interface MyView1 : UIView { ... }
-(id)initView1WithFrame:(CGRect)frame;
@end
...

and create 2 instances of MyView1, and add them as subviews of view2 and view3 respectively:

MyView1* view1a = [[MyView1 alloc] initWithFrame:...];
[view2 addSubview:view1a];
[view1a release];

MyView1* view1b = [[MyView1 alloc] initWithFrame:...];
[view3 addSubview:view1a];
[view1b release];
KennyTM
Your answer could solve my problem!Thanks a lot!
www.ruu.cc