Skip to content

Instantly share code, notes, and snippets.

@lborsato
Last active August 29, 2015 14:11
Show Gist options
  • Save lborsato/23748fb69db3c0e9a0c6 to your computer and use it in GitHub Desktop.
Save lborsato/23748fb69db3c0e9a0c6 to your computer and use it in GitHub Desktop.
iOS - Create tab controller with view controllers
// Create a tabbar controller and an array to contain the view controllers
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] init];
// Setup first view and nav controllers
UIViewController *vc1 = [[UIViewController alloc] init];
UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
[localViewControllersArray addObject:nc1];
// Setup second view and nav controllers
UIViewController *vc2 = [[UIViewController alloc] init];
UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
[localViewControllersArray addObject:nc2];
// set the tab bar controller view controller array to the localViewControllersArray
tabBarController.viewControllers = localViewControllersArray;
[self.window setRootViewController:self.tabBarController];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment