Reputation: 38803
In IB, I can set the bottom bar as a tab bar for a view as below screen shot, but how can I set it by code in the implement(.m) file?
Thanks
Upvotes: 0
Views: 1304
Reputation: 48398
Create an NSArray
of the UIViewController
s that you want to use. Then instantiate a UITabBarController
and set the viewControllers
property to this array. Then add the view
of the tabBarController
to the window. All this should be done in the AppDelegate.m file. For example:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *vc1 = [[UIViewController alloc] init];
UIViewController *vc2 = [[UIViewController alloc] init];
CustomViewController *vc3 = [[CustomViewController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
[vc1 release]; [vc2 release]; [vc3 release];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:viewControllers];
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
return YES;
}
Upvotes: 3