PDA

View Full Version : Tab Bar without Tab Bar Controller?




Buckeyes1995
Mar 30, 2011, 06:11 AM
This is probably a stupid question.. and maybe I'm not looking at this the right way.. but here goes.

The app that I'm working on is structured as follows (not to scale obviously):

--------------------------------------
| Title Label |
--------------------------------------
| |
| |
| Work Space View |
| |
| |
| |
---------------------------------------
| |
| Tool Kit View |
| |
| |
---------------------------------------
| |
| Tab Bar (3 buttons) |
---------------------------------------


The Label and Tool Kit views are all static. I used a Tab Bar element (NOT a Tab Bar Controller) from IB. All I want to do is change the Work Space View to another view to another view when the various buttons on the Tab Bar are pressed. Seems easy.. but I cannot figure out in IB how to hook up the IB Actions.. it appears the elements on the Tab Bar (buttons) can't be hooked up to IB Actions? Do I have to do this all programatically?

Do I NEED to use a Tab Bar Controller? If so, what's the purpose of the Tab Bar Element? I've searched all around and can't find any examples or documentation on using a Tab Bar in IB, other than in relation to a TB Controller.

Thanks, and sorry if this is obvious or dumb in advance :D



jnoxx
Mar 30, 2011, 06:32 AM
It's not that hard to add a tabbarcontroller, and has some really neat delegate methods for switching from nibs etc.
Why don't you just try that? :p

dejo
Mar 30, 2011, 09:48 AM
Seems to me a UIToolBar rather than a UITabBar would satisfy your needs.

Buckeyes1995
Mar 30, 2011, 12:24 PM
Seems to me a UIToolBar rather than a UITabBar would satisfy your needs.

I had considered that.. I just like the Tab Bar look better.

Just for my knowledge, what is the purpose of the IB Tab Bar element.. it would seem I could connect IBAction outlets to it to 'do things', but I can't figure out how.

I'm not opposed to a Tab Bar Controller.. just more curious now than anything else.

Thanks.

ulbador
Mar 30, 2011, 12:35 PM
You need to read a bit on iOS and how View Controllers fit and glue everything together. The basic point of having a separate UITabBar element is that the UITabBarController actually contains one. While you can use it separately, that's really not the way it's meant to be used nor is it a good practice to get into.


http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html

dejo
Mar 30, 2011, 12:38 PM
Just for my knowledge, what is the purpose of the IB Tab Bar element.

From the Quick Help for UITabBar:
The UITabBar class implements a control for selecting one of two or more buttons, called items. The most common use of a tab bar is to implement a modal interface where tapping an item changes the selection. Use a UIToolbar object if you want to momentarily highlight or not change the appearance of an item when tapped. The UITabBar class provides the ability for the user to customize the tab bar by reordering, removing, and adding items to the bar. You can use a tab bar delegate to augment this behavior.

it would seem I could connect IBAction outlets to it to 'do things', but I can't figure out how.
That's not normally how tab bars are used. Rather, you assign it a delegate and then use the delegate method(s) to respond to events.

Buckeyes1995
Mar 30, 2011, 12:51 PM
From the Quick Help for UITabBar:



That's not normally how tab bars are used. Rather, you assign it a delegate and then use the delegate method(s) to respond to events.

I completely missed the delegate reference in the documentation. That clears it up.

Thanks :D

Buckeyes1995
Mar 31, 2011, 06:38 AM
Thanks for mentioning the delegate use for the Tab Bar.

I have it working perfectly now... but I'm still puzzled by what the 'Tab Bar' is really for (yes, I'm probably way overthinking this.. but I hate to blindly use something and not understand it).

Everything I could find says that the Tab Bar Controller is the way you're "supposed " to implement tab bar applications. If so, why is the Tab Bar element included in IB? And when would you use it.

I'll probably go back and use a Tab Bar Controller instead of a Tab Bar w/ delegation, but at least I learned how to use it :D

dejo
Mar 31, 2011, 10:17 AM
...but I'm still puzzled by what the 'Tab Bar' is really for (yes, I'm probably way overthinking this.. but I hate to blindly use something and not understand it).

Everything I could find says that the Tab Bar Controller is the way you're "supposed " to implement tab bar applications. If so, why is the Tab Bar element included in IB? And when would you use it.
I'm not sure it's a cut-and-dry as you might like (as with much programming) but my understanding is that you use a UITabBarController when you want to set up custom view controllers for each tab (hence its viewControllers property). You would use UITabBar when you want the look and functionality of tab bar but don't have the above situation, say, only a single view controller. UITabBarControllers provide other advantages, such as the "More view controller" that you don't get with a simple UITabBar. Hope that helps.