views:

121

answers:

3

Hello,

I have a problem building applicatin with tabBarController. There is no problem doing tabBarController with navigationController if I build it from AppDelegate.

But now I have experienced problem when I want to create new view with tabBarController (3 tabs and each has navigation controllers) after a push from previous navigation controller. It simply doesnt work.

Here is the code:

MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainView_iPhone" bundle:nil];
mainViewController.tabBarItem.title = @"First";
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];

DictionariesViewController *dictionariesViewController = [[DictionariesViewController alloc] initWithNibName:@"DictionariesView_iPhone" bundle:nil];
dictionariesViewController.tabBarItem.title = @"Second";
UINavigationController *dictionariesNavigationController = [[UINavigationController alloc] initWithRootViewController:dictionariesViewController];

tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:mainNavigationController, dictionariesNavigationController, nil];

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

There is a problem after view is pushe to "First" controller. Application crashes...

Please for help.

Regards Borut

A: 

What are you trying to do with the following code?

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

You said that your app has 3 tabs and each of those tabs have a navigation controller. Therefore, what you should do is to add the navigation controllers to tabBarController.viewControllers (which you did), but then you need to set the tabBarController as the root view controller.

ryanprayogo
A: 

Yes, my app has 3 tabs and every one of them has his own navigatonController. I add one navigationController and view controller to each tabBarController. At the end I pushed everything on new view:

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

What do you mean that I need to set tabBarController as root view controller? Can you give me a piece of code showing how to do that ?

Thanks

borut-t
In your app delegate, do the following after adding all the nav controllers to the tabBarController.`[window setRootViewController:tabBarController];`
ryanprayogo
The problem is that I dont create tabBarController in AppDelete but on first subView. So there I can not access window property.If I summarize in short. In AppDelegate I first push navigationController and some view in in. After a button push in view I create tabBarController and I push it here and I'm not anymore in AppDelegate.Thanks
borut-t
A: 

I have done it this way and it works:

registerViewController = [[RegisterViewController alloc] initWithNibName:@"RegisterView_iPhone" bundle:nil];
AppDelegate_Phone *delegatePhone = [[UIApplication sharedApplication] delegate];
[delegatePhone.firstViewController.navigationController pushViewController:registerViewController animated:YES];

Thanks for your help guys.

borut-t