"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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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...