Here is the rootviewcontrollerdelegate definition
@protocol RootViewControllerViewDelegate
-(void)toggleView:(UIViewController )newController viewController:(UIViewController)oldController;
@end
a possible implementation to toggleView
-(void)toggleView:(UIViewController *)newController viewController:(UIViewController*)oldController {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([oldController.view superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
[newController viewWillAppear:YES];
[oldController viewWillDisappear:YES];
[oldController.view removeFromSuperview];
[self.view addSubview:newController.view];
[oldController viewDidDisappear:YES];
[newController viewDidAppear:YES];
[UIView commitAnimations];
[oldController release];
}
This will swipe the view controllers by flipping the view
Obviously you must make a new RootViewController somewhere and start with a view there, (could be the app delegate)
Now if you want a ViewController to be able to use the RootViewController it must conform to the protocol, you declare it in that classes interface like so
@interface MyViewController : UIViewController <RootViewControllerDelegate> {
id delegate;
}@property(assign) id <RootViewControllerViewDelegate> delegate;
Now you can use the delegates method to swap a view for another given that everything has been initialized right. the code to swap two controllers view could look like this
NewViewController *viewController=...
//you can set up your viewControllers data here if you need to
//Since its probable that this view has that data it can just set it instead of
//delegating
viewController.delegate=delegate; //setting up the RootViewController reference
[delegate toggleView:viewController viewController:self];
remember on the toggleView call back to release the old ViewController, if you dont youll get a leak since you lose all reference to that controller.