I'm building an iPad app and want to switch one of my subviews for another by pressing a button. I've been reading the documentation and this guide:
View Controllers: How to switch between views programmatically?
But I keep getting errors and the animations doesn't really happen, the views just switch immediately.
I'll paste some code below for context. I have a main view which has in it a sub uiview. In the sub uiview, there is another view. I want to swap the other view with another.
self.settingsViewController = [[GHPSettingsViewController alloc] initWithNibName: @"GHPSettingsViewController" bundle: nil andParent: self];
UIView *outerView = [self.containingView viewWithTag:0];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration: 100.25f];
[UIView setAnimationDuration: UIViewAnimationCurveEaseInOut];
if (self.settingsViewController.view.superview == nil) {
// Flip Out Old View
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.containingView cache:YES];
[self.settingsViewController viewWillAppear: YES];
[outerView removeFromSuperview];
[self.containingView insertSubview: self.settingsViewController.view atIndex: 0];
[self.settingsViewController viewDidAppear: YES];
}
[UIView commitAnimations];