High Order Blog

Building a company from the bottom up.

Just Put Your Modal View in a UINavigationController

Comments

You’ll end up doing it eventually, anyway. Here’s the situation: you need a modal view with a standard navigation bar, much like the “Log In” view in Twitbit:

Twitbit Log In View

It’s really easy to convince yourself that you just need this view to collect some basic info and be done with it. It won’t need to push other views onto a stack; it will always be the root of the modal view controller. So what do you do? You manually throw a navigation bar in your nib file, slap some buttons and a title on there and you’re done right?

No, you’re not done. You were wrong — you’ll need this view to appear in a stack of views, and sometimes it won’t be at the root of the modal view controller. In this case, I needed to add a help view. Save yourself the trouble and just wrap your view in a navigation controller from the get-go. Set its navigation item (why can’t you do this in Interface Builder, by the way?) and always put your view in a UINavigationController and you’ll have a more portable view. You win.

While I’m on the topic, does anybody else build just about every interface in IB only to redo it in code? Don’t get me wrong, I like the idea of IB, but it seems like there’s always something, whether that’s optimizing drawing, controlling initialization, or realizing everything is a table view cell, anyway, and you don’t need to lay anything out.

Written by Doug

September 16th, 2009 at 12:53 pm

Posted in Programming

blog comments powered by Disqus