I’ve added subview (ViewController) to my ViewController:
Location *location = [[Location alloc] initWithNibName:@"Location" bundle:[NSBundle mainBundle]];
[self.subView addSubview:location.view];
How can I latter remove this subview?
I know that for removing all subviews is:
for (UIView *subview in [self.view subviews]) {
[subview removeFromSuperview];
}
Quick and dirty: Give your view a tag, so you can later identify it:
Then, to remove:
A cleaner, faster, easier to read and to maintain alternative would be to create a variable or property to access the view:
In the interface:
In the implementation:
Then, to remove:
That said, heed the warnings from commenters about playing with other ViewControllers’ Views. Read up on ViewController containment if you want to do it.