I need to add a view to multiple views in app.
I am running a function which loops through all the UIViews and add that view as subview.
I have done something like this:
-(void) setViewForEachSegment: (UIView*)view {
int i;
for (i = 0; i < [segments count]; i++) {
[[segments objectAtIndex:i] addSubview: view]
}
}
here segments is an array of UIViews.
Now, what is happening is that the subview is added only to the last segment.
Has anyone else faced the same problem? I have been working on it for many hours, but don’t know how to fix it.
you can’t add one view into multiple views, because a view could have single parent view at a time. which is represented by
superViewproperty of yourUIView.Each time Create a new object of your
UIViewbefore adding to View,