I want to make a tab bar controller and navigation controller programmatically. My code works so far that it shows a tab bar at the bottom, but the OptionViewController doesn't say anything (no title) on the button of the second tab bar. The funny thing is, when i click the button without anything on it, the title appears (and so is his view), can someone explain to me what i am doing wrong? I tried to use the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
return YES;
}
I created the
UITabbarController
as rooview controller of the app withUINavigationController
for UIViewController.here one more example: I used xibs for View Controllers.
AppDelegate.m
I create a method name:
setupAppHome
It is texted in Xcode 9 with iOS 11.
If someone needs a SWIFT version. This worked for me. Thanks @rckoenes for the objC answer I used to translate this from.
You need to set the tabBarItem and title of the
UINavigationController
and not its root viewController.