views:

79

answers:

3

Hi,

As title says, I'm wondering if stacking subviews can slow down an iPhone application.

For example, I have a UIViewController, which has a view occupying the whole screen. When the user presses a button, I create a second view controller and add its view as a subview of the original VC, making the second view completely hide the first one.

Does the application have some kind of automatic optimization which would be something like "ok, I know what to draw for every pixel of the screen, I stop seeking for subviews" ?

If not, I don't think stacking 2 full-screen views can really slow down the app, but could 3, 4 or more views be problematic if they include many subviews themselves (labels, images)?

+1  A: 

This is largely dependent of what the subviews contain and what is the total memory load of the app. Memory is very crucial for devices like iPhone and you should never keep the things which you don't require. When you are adding many subviews without releasing any, your memory requirement obviously will increase. This may slow down the app, even may crash the app. Stacking of two may not be a problem, but stacking many is not a very good design.

So the summary is you should always check the memory load of the app through instrument and always properly respond to memory warnings.

taskinoor
Right, I did not think about the memory usage, which is crucial as you said. I'll try to find a better way to do.
Jukurrpa
+4  A: 

Read the View Controller Guide sections on Modal View Controllers and memory management. Prefer to use modal Views instead of subviews when you want to present a new screen temporarily and a UINavigationController for "drill-down" views.

falconcreek
Thanks for the link to the guide. I think Combined view controllers is better for me though, as my app is already something like this, it has a tab bar controller, and each tab has its own navigation bar.
Jukurrpa
+1  A: 

You can always set UIView#hidden = YES on the views not seen. That should prevent redraws.

ZaBlanc
That can be useful too. Thanks.
Jukurrpa