Need Help with iPhone SDK Layout... TabBarController? ViewController?

Discussion in 'iPhone/iPad Programming' started by Littleodie914, Jun 29, 2008.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Hey guys :)

    I recently switched over from designing my iPhone layouts programmatically to inside IB, and I can't say I'd recommend it just yet. Here's what I'm trying to accomplish:

    I have a UINavigationController, handled by the delegate. It pushes the first view controller on at launch time, then each view controller from then on just uses [self.navigationController push...] yadda yadda.

    Now, picture this as a completely linear, horizontal layout. So I have something like:

    NavController (On Top)

    ViewController -> ViewController -> View Controller

    Not too difficult. *BUT* now I want to add a fourth view controller to the end, that is actually a TabBarController, and that's where I'm having issues. I'm currently doing this:

    ViewController -> ... -> ViewController (which, at init, performs a [self.view addSubview:tabBarController.view])

    This works *ok*, but I'm getting a very strange issue where the top of that view is blank! It looks like:

    <Status Bar>
    <Navigation Bar>
    <20px of Blank Space> (status bar size?)
    <Root View of TabBarController>
    <TabBar>

    (Am I allowed to attach pictures? If I am, I will. :))

    So does anyone know what I'm doing wrong? I can't figure it out for the life of me! In IB, that first view has a simple tableview, which is set to fill by default, and then the tab bar at the bottom. Has anyone else run into this problem? Thanks!! :D
     
  2. macrumors newbie

    Joined:
    May 26, 2008
    #2
    If u want the tabBar to be shown in all screens/views, then after adding the views to the navigationBar, u need to add the navigation bar to the tabBar.

    From the documentation of the view hierarchy, u'll see that tabBar 'contains' navigationBar.
     
  3. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #3
    But that's the thing, I don't want the tab bar to be on all of the screens. Here's how it should flow, in terms of what's visible on the screen:

    #1
    NavigationController
    View

    |
    V

    #2
    NavigationController
    View

    |
    V

    #3
    NavigationController
    View
    TabBar

    (Except picture that going horizontally, instead of vertically.) So I have a ViewController in IB that has an outlet to a TabBarController. So when I'm in view #2, and I try to push a view controller, should I push the ViewController in IB that has the TabBarController? Or should I push the TabBarController itself? That's where I get confused. When I do this:

    [self.view addSubview:tabBarController.view];

    In the ViewController that I push, the View shows up, but there's no TabBar at the bottom.

    Edit: Re-reading this post confuses even me. I wish Apple would post more documentation/samples.
     
  4. macrumors 6502

    Joined:
    Apr 28, 2008
    #4
    I had the same thing with one of my Views. I had a label sit flush with the bottom of my View in Interface Builder, and when I ran the program it was no where to be seen! I soon realized that if I configured the app to not render the status bar (it's a property you can set in Info.plist, sorry don't know it off the top of my head), then it showed up... Apparently, the view was being rendered but the status bar was pushing the view down so to speak.

    Try moving these things up in your TabControllerView by 20px or turning off the status bar for your app and see if that fixes things.
     
  5. macrumors newbie

    Joined:
    May 26, 2008
    #5
    I guess that you are writing the above line of code in the loadView method of that viewController which you want to show up with the TabBar. DON'T do this, instead, add the 'simple' viewController to the TabBar where you are creating that viewController's instance.

    and then, push the TabBarController to the navigationController.

    I also checked this before posting :)
     
  6. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #6
    Bingo :D

    Thanks a lot!
     
  7. macrumors newbie

    Joined:
    Aug 27, 2008
    #7
    Can you please elaborate and explain? I'd love to achieve this same end result, but do not understand your solution.

    Thanks so much!
     

Share This Page