PDA

View Full Version : Need Help with iPhone SDK Layout... TabBarController? ViewController?




Littleodie914
Jun 29, 2008, 09:47 AM
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
Jun 30, 2008, 12:33 AM
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
Jun 30, 2008, 03:28 PM
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
Jun 30, 2008, 04:31 PM
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
Jul 1, 2008, 01:35 AM
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
Jul 1, 2008, 08:38 AM
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!

vosens
Jan 20, 2009, 12:20 PM
Bingo :D

Thanks a lot!

Can you please elaborate and explain? I'd love to achieve this same end result, but do not understand your solution.

Thanks so much!