Skip to content

Instantly share code, notes, and snippets.

@kmav
Last active March 26, 2023 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmav/117839d62f6ca80634c894fb7d1e9c05 to your computer and use it in GitHub Desktop.
Save kmav/117839d62f6ca80634c894fb7d1e9c05 to your computer and use it in GitHub Desktop.
iOS programmatically add UITabBarController with UINavigationController instances as tabs using Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FeedTableViewController *feedTableViewController = [[FeedTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *feedNavController = [[UINavigationController alloc] initWithRootViewController:feedTableViewController];
ProfileViewController *profileController = [[ProfileViewController alloc] init];
UINavigationController *profileNavController = [[UINavigationController alloc] initWithRootViewController:profileController];
FavoritesViewController *favController = [[FavoritesViewController alloc] init];
UINavigationController *favNavController = [[UINavigationController alloc] initWithRootViewController:favController];
// create tabController and add sub-controllers
UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.viewControllers = @[feedNavController, favNavController, profileNavController];
// set rootViewController
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment