views:

494

answers:

3

Hi,

I have a view controller and I want to host a UITabBar on it. When the user clicks on different tab items, I want to show different views. I have this working, but it's hard to maintain.

In InterfaceBuilder, I simply created all my tab views, hide them. In my project, when the user clicks on one of the tab items, I simply set the hidden property of the linked view to false so it appears.

The xib looks like a disaster though, because I have about 4 views layered on top of one another. To make things easier, I set the hidden property to true in InterfaceBuilder for the views, hoping it would completely hide some so it's easier to see what I'm doing. InterfaceBuilder simply changes the view's opacity to like 30% though, so you still see them all layered on top of one another.

I'm wondering if there is a better way to do this. I don't want to programatically generate all the views for this UI if possible.

Thanks

+4  A: 

UITabBar should really be the 'root' container for your interface, and then it should contain navigation controllers and/or views.

I find that when the UI itself becomes difficult to deal with in Interface Builder, the best thing to do is switch to outline view in the Nib window (use the "View Mode" toolbar item), and access the elements in the Nib window's hierarchy.

Fraser Speirs
+1 Outline view is the closest IB comes to handling a scaling-up of complexity. As an alternative, if you happen to have an exceedingly complex UI with lots of rich and *dynamic* content, I'd recommend considering Three20 for its TTStyledText and TTStyleSheet mechanisms.
Justin Searls
A: 

I generally dislike creating all sorts of hidden views within a nib file, precisely because of how messy things get and how easy it becomes to inadvertently click and drag something you don't intend to.

What I'll do instead in that instance is break out the hidden views into separate nibs, and have the controller load and place them into the view on an as-needed basis. Another upside to this approach is that it loads views only when they're needed - making the view lighter-weight overall.

MrO
A: 

I have the same problem but instead of using the Hidden checkbox, I go the Size inspector for the controls I want to "hide", and then just put a 99 before the X value. This moves it off the screen, and it's easy to move it back to the original location by removing the 99. Not ideal, but it works... just remember to move them back when you're done.

chaiwalla