google

iOS application with Tab Bar and Navigation Bar for Tabbed navigation as well as Back Forward Navigation.

| Saturday, January 5, 2013

For developing an application with tab bar and navigation bar, create a new Xcode project with Tabbed Application Template.

The AppDelegate header file should look like this

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UITabBarController *tabBarController;

@end

and AppDelegate implementation file will contain the definition of all the view controllers which are to be placed in the Tab Bar of the application and Title of those controllers will be displayed in the Navigation Bar.

The - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method will contain definition and initialization of the view controllers 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    
    UIViewController *view1, *view2,*view3,*view4,*view5;
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        view1 = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        view2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];
        view3 = [[View3 alloc] initWithNibName:@"View3" bundle:nil];
        view4 = [[View4 alloc] initWithNibName:@"View4" bundle:nil];
        view5 = [[View5 alloc] initWithNibName:@"View5" bundle:nil];
    } else {
        view1 = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    UINavigationController *nav1=[[UINavigationController alloc] initWithRootViewController: view1];
    UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController: view2];
    UINavigationController *nav3=[[UINavigationController alloc] initWithRootViewController: view3];
    UINavigationController *nav4=[[UINavigationController alloc] initWithRootViewController: view4];
    UINavigationController *nav5=[[UINavigationController alloc] initWithRootViewController: view4];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = @[nav1, nav2, nav3, nav4, nav5];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

The above code holds the key for displaying the view controllers with Navigation bar. Please import header files of all above controllers in the AppDelegate.

If we add controllers directly into the self.tabBarController.viewControllers then all the controllers will open without the Navigation Bar.

In the each view controllers' initWithNibName set the title and image to be displayed with the Tab.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"View 1", @"View 1");
        self.tabBarItem.image = [UIImage imageNamed:@"star"];
    }
    return self;
}

Add star named image in the project.

To open a new view controller with Back navigation on the Navigation Bar along with the Tab Bar at the bottom, Open the new view controller on a button touch up inside or any other action as follows.


 ViewController1 *view1 = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
  [self.navigationController pushViewController: view1 animated:YES];


And you have the app ready with Tabbed Navigation at the bottom and Navigation Bar at the top.

Build and run the project.

The App will look something like this.

























Please provide your feedback!! Thanks.






2 comments:

  1. I was looking for this one for so long!!

    ReplyDelete
  2. The particular tests conducted were being separate regarding Cree associates and managed utilizing digital camera timers, fixed kilometers, laserlight range meters, two distinct foot or so candle meters, and a laserlight cold weather assess. Just about all tests were being conducted from a single analyze platform to make sure uniformity. Just about all sizes were being taken by means of products attached with a new tripod, and timers were being utilized in which relevant. Just about all products has been calibrated prior to screening and kilometers were being established. Generally speaking, I found that this tests established Cree's statements in cause.Lámparas

    ReplyDelete

Next Prev
▲Top▲