I have a MainWindowController that I want to close on "touch inside" button event and open a new UIView. The code that I use is this:
NewViewController *controller = [[NewViewController alloc]
initWithNibName:@"NewView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
But in this way the MainWindowController don't close it self.
You should use a UINavigationController to manage the push and pop of UIViewControllers. In the UINavigationController you should define a root view controller, child view controllers are added over it like layers.
you could have a root and add a child to it. When you press the button, pop the child and make the root push another child.
the action would be something like:
root push child1 (root is covered by child1)
root pop child1 (root is visible)
root push child2 (root is covered by child2)
here's a link to UINavigationController documentation.
if you want to remove UIView's from an UIViewController then you don't need a UINavigation controller. You can create 2 UIView's in your viewController and swap them when you push the button.
1) Create a UIView to hold the swapped views(container)
2) Construct your UIViews that you want to swap between. Put them in an array.
3) Hook your button up to an action method. This method should figure out the index of the view that needs to be shown, remove all of container's subviews, add the subview [viewsArray objectAtIndex:nextViewIndex] to container.