1

I have a window based app. I added two viewcontrollers and one Tabbarcontroller to that. Now I want to navigate each viewcontroller to next view. I tried but can't find the solution. Can anyone please help me?

1
  • 1
    Post up your code and it might be easier to see why things aren't working for you. Commented Mar 4, 2011 at 5:23

3 Answers 3

2

When you add the tab bar on window, add like this-

NSMutableArray * viewControllers = [[NSMutableArray alloc]init];


FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];

SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
 nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];

UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];

EDIT - Whenever you want to navigate in any one of the controller. All you need is to call

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

And you will get exactly what you want. :)

Sign up to request clarification or add additional context in comments.

Comments

1
UINavigationController *urNavController = [[UINavigationController alloc] initWithRootViewController:rootController];

If you want to show this on the window

[window addSubview:urNavController.view];

Comments

1

use like this

secondViewController *obj=[[[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil] autorelease];
      UINavigationController *navBar=[[UINavigationController alloc] initWithRootViewController:obj];
      [self.navigationController pushViewController:navBar animated:YES];

      [navBar release];

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.