Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Views within one XIB - iPhone SDK

Tags:

iphone

xib

I have been spending time learning how to use the iPhone SDK. I've read "Beginning iPhone Development: Exploring the iPhone SDK" from cover to cover and I've never seen an example of multiple views within one XIB.

To illustrate what I mean, here is a screen shot of a XIB with the simple configuration of what I'm referring to:

alt text http://theopensourceu.com/wp-content/uploads/2009/04/one-xib-multiple-views.png

I figure that there has to be a very specific reason that I've never seen this. In Apple's examples and in all of my readings thus far, multiple XIBs are used with only a single 'view' (and sometimes the Navigation Controller or a Tab Bar Controller, etc). What is the reason for this? Should I avoid multiple views inside a XIB? What are the advantages or disadvantages to to either method?

Thank you in advance

like image 282
Frank V Avatar asked Apr 19 '09 14:04

Frank V


1 Answers

It's a question of memory optimization and loading times. If you put all your views in one XIB, then when your application launches, it has to load the entire XIB into memory and construct all of the objects for all of the controls, and this takes a non-trivial amount of time.

If instead you separate your views into separate XIBs, then your app will start up much faster, because only the XIB containing the initial view will be loaded, and it will also use less memory at first. Then, when the view changes, you can load the XIB containing the new view lazily. This will incur a minor hitch when opening a view for the first time. If you're really trying to optimize memory use, you can also unload the previous view when switching views, but I wouldn't recommend this, as this will incur a hitch every time you switch views, instead of just the first time you switch to any given view.

like image 97
Adam Rosenfield Avatar answered Sep 28 '22 00:09

Adam Rosenfield