Search code examples
objective-cuinavigationbaruitabbar

Objective C: Show Nav and Tab Bar


I am buiding an app with an UIWebView, a UITabBar, and multiple other views, each one for a Tab. I want to show the Nav bar, Tab bar and the view in one go. When I type this:

    -(BOOL) (UIApplication *) application ApplicationDidFinishLaunchingWithOptions: (NSDIctionary *) launchOptions {
[_window addSubView: tabController.view];
[_window addSubView: navController.view];
[self._window makeKeyAndVisible];
return YES;
}

I get everything I want, but i cannot click the Tab Bar (I see it, it lods all right). The button I made works in the Nav bar, but I cannot click the Tab Bar tabs. When I swap them:

  -(BOOL) (UIApplication *) application didFinishLaunchingWithOptions: (NSDIctionary *) launchOptions {
    [_window addSubView: navController.view];
    [_window addSubView: tabController.view];
    [self._window makeKeyAndVisible];
    return YES;
    }

I get my TabBar, with clickable tabs, but no Nav Bar. I don't even see it. So, my structure is:

-Window:
  -TabBarController:
    -> View1.xib
      -UIWebView
      -UINavigationBar
    -> View3.xib
      -UIWebView
      -UINavigationBar
    -> View3.xib
      -UIWebView
      -UINavigationBar

Any ideas?


Solution

  • Generally, you can't add both nab and tab bar controllers to a window. Usually the structure is:

    • Window
      • TabBarController
      • Controller of tab 1
        • NavigationController of tab 1
      • Controller of tab 2
        • NavigationController of tab 2
      • Controller of tab 3
        • NavigationController of tab 3
      • Controller of tab etc.
        • NavigationController of tab etc.

    That allows to have different navigation controllers for different tabs. And single tab pane for an application.

    It's possible to invert the structure and to have a Navigation Controller on the top of it and tabs somewhere lower. But it's not a normal usage of these components.

    I want to mention, that you can add only TabBar's view to window, all other views are handled by controllers.