0

I'm using Xcode 4.4.1. I have created a simple tabbed based application. And then I want to add navigation controller to the application. Can any one tell me how to do that in Xcode 4.4.1. My current code is like this but it doesn't work.

`

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[Addbills alloc]initWithNibName:@"Addbills" bundle:nil];
UIViewController *viewController3 = [[CalenderView alloc]initWithNibName:@"CalenderView" bundle:nil];
UIViewController *viewController4 = [[Web alloc]initWithNibName:@"Web" bundle:nil];
UIViewController *viewController5 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];
[self.navigationController setNavigationBarHidden:TRUE];


self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1,viewController2,viewController3,viewController4,viewController5];
self.window.rootViewController = self.tabBarController;

// self.window.rootViewController =self.navigationController;

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;

}

`

and this is my button click event in viewController5

`

 - (IBAction)backToPrevious:(id)sender {


[self.navigationController popToRootViewControllerAnimated:TRUE];

}`

Thanks,

iDia
  • 1,397
  • 8
  • 25
  • 44

1 Answers1

0

Here is how you should do it.

// initialize the tabbar controller
UITabBarController *tabbarController = [[[UITabBarController alloc] init] autorelease];

UIViewController *itemsViewController1 = [[[UIViewController alloc] initWithNibName:@"SomeViewController1" bundle:nil] autorelease];
UINavigationController *itemsNavigationController1 = [[UINavigationController alloc] initWithRootViewController:itemsViewController1];

UIViewController *itemsViewController2 = [[[UIViewController alloc] initWithNibName:@"SomeViewController2" bundle:nil] autorelease];
UINavigationController *itemsNavigationController2 = [[UINavigationController alloc] initWithRootViewController:itemsViewController2];


tabbarController.viewControllers = @[itemsNavigationController1,itemsNavigationController2];

_window.rootViewController = tabbarController;
SarpErdag
  • 781
  • 1
  • 8
  • 19
  • since I have 5 tabs I created 5 objects for each tabs in AppDelegate.m And in 5th viewcontroller btn click as [self.navigationController popToRootViewControllerAnimated:TRUE];but it not goes to another page – iDia Aug 16 '12 at 07:01