Reputation: 1001
I'm trying to do something a little tricky with UIViews in an iPad app. Take this view structure for example:
View 1 > View 2 > View 3
Note that the 3 views are all the same size and are all being shown on top of each other. View 1 is the parent of View 2, View 2 is the parent of View 3. The user is currently seeing View 3 as it is on top.
I want to delete View 2 and attach View 3 with all it's subviews onto View 1 -- without altering the current display. Basically, get rid of View 2 in the background. I cannot use removeFromSuperview
as if I do that, it will also remove View 3 (which is what the user is currently looking at).
I realize it would probably make more sense to have all 3 of the views be a child of an additional parent view and that way I could just removeFromSuperview
as I please -- however I'm really just curious if anyone has made something like I described above work.
Upvotes: 0
Views: 305
Reputation: 69027
If I understand correctly what you are trying to do, this should work:
[view1 addSubview:view3];
[view2 removeFromSuperview];
From UIView
class ref:
Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.
Upvotes: 1