1

I'm developing an iphone app where the First four screens are navigation based.

From fifth screen the design changed to a Tabbar based one.In this tabbar based section we are able to navigate the subviews on each tab.

How could I implement this?

Where do I declare the tabbar Controller-In appDelegate or in some other files?

4 Answers 4

1

You can add observer in your app-delegate class

[[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(youMethod)        
                                                 name:@"loginSucess" 
                                               object:nil];


- (void)youMethod
{
    UINavigationController *controller = [[[UINavigationController alloc] initWithRootViewController:self.tabBarController] autorelease];


    self.window.rootViewController = controller;    
    [self.window makeKeyAndVisible];
}

and for the action were you want to add your tabbar you can call like this

    [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSucess" object:nil];
0

in app delegate you declared the first 5 screens (Screen 1 to 5) Lets say on a button of screen 5 you want to launch a tab bar You do the following:

//Create the tab bar controller
UITabBarController *tabBar = [[UITabBarController alloc] init];
//Create the 5 new view controllers
UIViewController *cont_1 = [[UIViewController alloc] init];

//Add them to array
NSArray *arr = [NSArray arrayWithObjects:cont_1, cont_2, ... , nil]
[tabBar setViewControllers:arr];

//Now push the tab bar controller
[self.navigationController pushViewController:tabBar animated:YES];
0

i too had a similar prob in my app and finally i came up with pushing another UIViewController and adding the UITabBarController view as a subview.

when u are on your 4th screen and u navigate to the 5th screen which is also a UIViewController. and i am supposing u hv 3 tabs.

in viewDidLoad of this UIViewController

UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIViewController1 *objUIViewController1 = [[UIViewController alloc] initWithNibName:@"UIViewController1" bundle:nil];
UIViewController2 *objUIViewController2 = [[UIViewController alloc] initWithNibName:@"UIViewController2" bundle:nil];
UIViewController3 *objUIViewController3 = [[UIViewController alloc] initWithNibName:@"UIViewController3" bundle:nil];

tabBarController.viewControllers = [NSArray arrayWithObjects:objUIViewController1, objUIViewController2, objUIViewController3, nil];
tabBarController.delegate = self;
[[tabBarController.viewControllers objectAtIndex:0] setTitle:@"Title1"];
[[tabBarController.viewControllers objectAtIndex:1] setTitle:@"title2"];

[self.view addSubview:tabBarController.view];
[UIViewController1 release];
[UIViewController2 release];
[UIViewController3 release];

hope it helps. happy coding :)

0

Create Tabbar controller prgrammatically and add tabbarcontroller into navigationController

MyFirstViewController *myFirstViewController = [[MyFirstViewController alloc] init];
MySecondViewController *mySecondViewController = [[MySecondViewController alloc] init];

myFirstViewController.array = self.array;


NSArray *array = [[NSArray alloc] initWithObjects:myFirstViewController, mySecondViewController, nil];
UITabBarController *tab = [[UITabBarController alloc] init];
tab.viewControllers = array;

[array release];

UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"first title" image:nil tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"second title" image:nil tag:2];

myFirstViewController.tabBarItem = item1;
mySecondViewController.tabBarItem = item2;



[self.navigationController pushViewController:tab animated:YES];

Use this code this will be useful to you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.