Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
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
 

aatif

macrumors newbie
May 26, 2008
10
0
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.
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
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.
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.
 

Enuratique

macrumors 6502
Apr 28, 2008
276
0
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

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.
 

aatif

macrumors newbie
May 26, 2008
10
0
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.

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 :)
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
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 :)
Bingo :D

Thanks a lot!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.