User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







objective-c:examples:tabbarcontroller

TabBarController

Add two UIViewController named RootViewController and SecondRootViewController to your empty project

Create a TabBarController for your project

First step import the RootViewController.h and SecondRootViewController.h in your AppDelegate

#import "RootViewController.h"
#import "SecondRootViewController.h"

2. Initialize RootViewController and SecondRootViewController
3. Initialize NavigationController with RootViewController
4. Initialize an array and add controllers for the tabbar
5. Initialize TabBarController
6. Add array of controllers to tabbar
7. Add tabbar to the window

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    // ** initialize window **
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 
    // Override point for customization after application launch.
 
    // ** initialize RootViewController **
    RootViewController *rootVC = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    SecondRootViewController *secRootVC = [[SecondRootViewController alloc] initWithNibName:@"SecondRootViewController" bundle:nil];
 
    // ** Set titles and images of the controllers to display them in each tab and the navigationController`s navigationbar **
    rootVC.title = @"Root NavCon";
    rootVC.tabBarItem.image = [UIImage imageNamed:@"one.png"];
 
    secRootVC.title = @"Second RootVC";
    secRootVC.tabBarItem.image = [UIImage imageNamed:@"another.png"];
 
    // ** Initalize NavigationController with RootViewController **
    UINavigationController *navVC = [[UINavigationController alloc]initWithRootViewController:rootVC];
 
    // ** Init array with controllers **
    NSArray *tabBarArray = [[NSArray alloc]initWithObjects:navVC, secRootVC, nil];
 
    // ** Init TabBarController **
    UITabBarController *tabCon = [[UITabBarController alloc]init];
 
    // ** Add Controllers to the tabBar **
    tabCon.viewControllers = tabBarArray;
 
    // ** Add NavigationController **
    self.window.rootViewController = tabCon;
 
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
objective-c/examples/tabbarcontroller.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz