Is there a UITabBar and UINavigationController in the application?

Hi everyone, I am new to iPhone development and I do not understand the idea of ​​UINavigationController and UITabBarController. Is this a replacement for the other - how do apps like Tweetie combine both?

I want my application to have a permanent @ tab bar at the bottom (which seems to work), but also a navigation bar at the top that can display / pop up on the screen without removing the tab bar.

  • How can i do this?
  • What should the hierarchy in IB look like before my MainWindow.xib for all of these controllers?
  • What is best here?

Many thanks,

+7
iphone uitabbarcontroller uinavigationcontroller
source share
2 answers

Just close the view controller in the UINavigationController and place the UINavigationController inside the UITabBar . This will work great for you ...

Example:

 NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2]; tabBarController = [[UITabBarController alloc] init]; [tabBarController setDelegate:self]; UINavigationController *navigationController = nil; navigationController = [[UINavigationController alloc] initWithRootViewController:<Your View controller1>]; [tabBarViewControllers addObject:navigationController]; [navigationController release]; navigationController = nil; navigationController = [[UINavigationController alloc] initWithRootViewController:<Your View controller2>]; [tabBarViewControllers addObject:navigationController]; [navigationController release]; navigationController = nil; tabBarController = tabBarViewControllers; [tabBarViewControllers release]; tabBarViewControllers = nil; 
+15
source share

Use the wizard to use the tab bar application and configure it as usual. On any tab where you want to add a navigation controller, create it in XIB using the library. My XIB has:

  - File Owner DescriptiveNameNavViewController
 - First Responder
 - View UIVIew
 - Navigation Controller UINavigationController
   - Navigation Bar UINavigationBar

Please note that there is nothing in the view. See ViewDidLoad below for a UINavigationController connected to a UIView.

There is no specific standard in the header file for the Tab ViewController (which I call DescriptiveNameNavViewController here, but I use [Something] NavViewController to remind me that this ViewController contains a navigation controller with This is the name of the controller that I set in MainWindow.xib, created by the wizard.) Configure the UINavigationController * IBOutlet with the navigation controller in the XIB attached to it:

 @interface DescriptiveNameNavViewController : UIViewController { UINavigationController *navigationController; } @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @end 

In the controller for DescriptiveNameNavViewController do something like this:

 - (void)viewDidLoad { [super viewDidLoad]; [[self view] addSubview:[navigationController view]]; DescriptiveNameController *aController = [[[DescriptiveNameController alloc ] initWithNibName:@"DescriptiveNameController" bundle:nil ] autorelease]; aController.title = @"Descriptive Title"; // // app stuff goes here. // [self.navigationController pushViewController:aController animated:YES]; [self.navigationController setDelegate:self]; } 

Setting up a delegate in DescriptiveNameNavViewController is very important, because otherwise you will not get the methods that you expect in instances of DescriptiveNameViewController, and everything else that you push on the navigation controller stack.

In the DescriptiveNameNavViewController, we implement the UINavigationControllerDelegate methods as follows:

 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([viewController respondsToSelector:@selector(viewDidAppear:)]) { [viewController viewDidAppear:animated]; } } 

And this will cause messages to propagate to controllers inside the UINavigationController, as you expect. It seems that many of the problems people face are related to the fact that viewDidAppear: or other methods are not called in the ViewControllers pushed into the NavigationController.

In any case, let me know if more details help.

+3
source share

All Articles