1

I had on my application 2 different views (one for Portrait and another for Landscape mode) and I would like to separate them into different XIB files so that I'm using less memory. I've done so but when changing my iPad's orientation my view becomes blank. I've tried to do the following:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
self = [[MyController alloc] initWithNibName:@"MyControllerLandscape" bundle:nil];
}

But it just initializes the view with no data (no images, no labels, ...). How can I "unload" the current view and "load" the new one with the interface orientation avoiding to pop the view and pushing a new one?

EDIT:

I've tried now this and it's more or less working:

[[NSBundle mainBundle] loadNibNamed:@"myPortraitView" owner:self options:nil];
[[NSBundle mainBundle] loadNibNamed:@"myLandscapeView" owner:self options:nil];

My question now is: if I do that on my init method, will it load both views into memory or just a reference to load the view when neded?

Alex
  • 481
  • 1
  • 5
  • 19

1 Answers1

2

Here's a nice example of implementing this via a navigation controller:

Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

Community
  • 1
  • 1
SVD
  • 4,743
  • 2
  • 26
  • 38
  • That's a nice solution but (please correct me if I'm wrong), is the guy using a controller for each landscape view and another one for the portrait mode? What I wanted to do is to load only 1 view in memory (the one which will be displayed) and remove the other one, just to save memory. Using that example I would only save memory in case the user does not rotate the device, is it? Thanx! – Alex Aug 23 '11 at 07:27
  • The two controllers will sit in memory, yes, but the inactive view will be able to unload if the app receives a memory warning. I suppose you could create the view controllers only when needed (that is, right before pushing them into the navigation controller) and release them after popping. This way you'll only have one view and one controller in memory, but of course it may be a performance penalty to load the view every time device rotates - although I doubt it will be noticeable, unless you have very complex views. – SVD Aug 23 '11 at 16:22