Skip to content

Instantly share code, notes, and snippets.

@tilomitra
Created April 22, 2010 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tilomitra/374649 to your computer and use it in GitHub Desktop.
Save tilomitra/374649 to your computer and use it in GitHub Desktop.
//The first example is adding a subview to your MainWindow nib so that it loads a nib from another view controller.
//The following code goes in the AppDelegate.m under the following method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
[window addSubview:switchViewController.view]; //replace switchViewController with your own viewController
[window makeKeyAndVisible];
return YES;
}
//The second example shows how to add subviews to a viewController
//This would go in the view controller you are adding subviews to.
- (void)viewDidLoad {
[super viewDidLoad];
//In this case, BlueViewController is a viewController that is being called in this viewController (switchViewController)
BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];
self.blueViewController = blueController;
[self.view insertSubview:blueController.view atIndex:0]; //index 0 determines zindex.
[blueController release];
}
//This example shows how to remove views (like the one above)
[yellowViewController.view removeFromSuperview];
//You can also check to see if the view of a given viewController is present using the following:
if (self.blueViewController.view.superview == nil) {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment