Last active
March 26, 2023 20:17
-
-
Save kmav/117839d62f6ca80634c894fb7d1e9c05 to your computer and use it in GitHub Desktop.
iOS programmatically add UITabBarController with UINavigationController instances as tabs using Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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