views:

886

answers:

4

I have a split view app running fine on the iPad. It is using the default setup (Popover in Portrait, table view on the left in landscape). The views shift correctly once the app is running. The problem I am seeing is that when the app starts (in the simulator) running in landscape mode the UI paradigm is the one intended for Portrait mode (Master List is a popover) is what loads.

I am thinking this is some strangeness with the simulator, or I am missing an option on my main view controller.

A: 

Adding this as an answer as well in the hopes it will be more apparent to those in need of the same fix.

I solved this. I was waiting for an external XML stream to be loaded & parsed. As a result I was loading the window with the splitViewController view AFTER my applicationDidFinishLaunching method.

Adding:

[window addSubview: splitViewController.view]; 
[window makeKeyAndVisible]; 

back into that method fixed the orientation recognition

MystikSpiral
A: 

I've got the same issue. I always like to add a loadingViewController instead of the main viewcontroller stucture, such as splitView or tabbar view controllers. This is so I can have a nice loading with animation that is aware of the orientation.

So I never load something like the splitViewController onto the window in the applicationDidFinishLaunching method, but rather after and ONLY after I know the rest of my app has finished loading and is ready for use, initializing core data, receiving possible over the air updates for data to core data.

So when I'm ready to actually display the splitViewController, I send the removeFromSuperView call to the the loadingViewController.view and it's removed from the window. I then proceed to add the splitViewController to the window via [window addSubview:splitViewController.view]. Everything works EXCEPT the same problem reported in this incident in that if I start the app in landscape mode, my loadingViewController is aware it's landscape and shows the landscape version of the loading screen. But when the splitViewController is displayed, it's always in a portrait sized window. It takes manually rotating and rotating it back for the landscape splitViewController to display properly.

Anyone got more ideas?

Yours truly,

Stumped in landscape

J to The bizzo
+1  A: 

I ran into the same problem as is described here. The solution was, embarrassingly, as simple as manually setting the view's frame before adding it to the window.

Just check the interface orientation and, if it's landscape, switch the application frame width and height dimensions (i.e., width becomes height, height becomes width).

CGRect frame = [[UIScreen mainScreen] applicationFrame];

switch(controller.interfaceOrientation){
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
      [controller.view setFrame:frame];
      break;
    case UIInterfaceOrientationLandscapeLeft:
    case UIInterfaceOrientationLandscapeRight:
      [controller.view setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width)];
      break;
}
I do not see this as embarrassing to you the developer; it is a deficiency in the SDK. There is no way this step should be required. Were you not using a Split View Controller in your app you would not have to take this step.
MystikSpiral
A: 

I succeeded into displaying a loading view by doing

[window addSubview:self._splitViewController.view];
[window addSubview:self._myLoadingView];
self._splitViewController.view.hidden = YES;
[window makeKeyAndVisible];
[self loadAllDatas];
self._splitViewController.view.hidden = NO;

i works fine

raphaelharboun
Does this work for you if you have a view that is NOT part of the SplitViewController loaded? Part of the issue is that I wanted to have a "loading" view appear. When I did this it threw everything off, including the orientation support doing things the way you outlined above.
MystikSpiral