views:

134

answers:

1

"When presenting a navigation controller modally, it is often simpler to create and configure your navigation controller object programmatically. Although you could also use Interface Builder to do so, doing so is generally not recommended." If fact, because my navigation controller is simple, I would rather customise the view in IB!

+3  A: 

While I don't know the exact reason, this is my shot at it:

When creating the controller programmatically, you need only a few lines of code, in fact, in most cases this might be really few: creating, setting the root controller, presenting and releasing. The alternatives are quickly enumerable:

  • You could hold the view controller as an outlet in the underlying controller. Then, however, it would reside in memory all the time. Would not only be waste of memory, but this also doesn't make too much sense while it's not needed.
  • You could instantiate that controller form a nib file. Then, however, you would have to do a lot of things that you'd do either way:
    • Create the controller in code with alloc,init
    • Set up some properties - either in a custom class, the nib or a few lines of code
    • Present it
    • Release it

Now, given that the alternative is only a few lines setup of code, the overhead of loading a nib file, which is in fact not extremely cheap, isn't really worth the additional comfort. If you are doing a lot of setup then this would go into a custom class anyways, no matter whether loading from nib or creating in code.

Just my thoughts...

Max Seelemann
good answer +1 :) interface builder is the devil and it will quickly become very apparent to any "serious" iphone programmer that doing everything programatically is a much better solution.
Thomas Clayson
i'm being a n00b at iphone programming and no one can stop me!
gurghet
Don't use Interface Builder, it's better to write it by hand. You can use IB to figure out the design, but don't use it in your final project. You mentioned you were a NOOb, watch these videos: http://www.eng.utah.edu/~cs4962/index.html You'll learn a lot, and Matt does not believe in using IB.
Brad
I'd not go so far to say "don't use IB". Rather use it where it makes sense and where it doesn't. A little ib file can save tons of ugly setup code. Not in the particular case discussed here, but in many others...
Max Seelemann