views:

139

answers:

3

So I have a UISplitViewController that is the root view of my program. I have set the initial orientation to be LandscapeLeft and have all 4 orientations supported in my plist.

If I launch the app in portrait - the view that is shown is my root view not the detail view which obviously is not what I want. As soons as I rotate the device, everything works from there.

I have scoured this site and others but have found no fixes. The closest I have come is the adding the following to my app delegate:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

if (UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation)) {
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
    else
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
}

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

So this essentially forces it to draw correctly, which works great except for when the app launches with the device laying flat. Then I dont know the portrait vs landscape (and I know of no way to find it). So I basically then cant accurately say what to do.

The larger thing is this above code is a HACK, and there should be a better way, but for the life of me I cant find it.

Any ideas?

A: 

Your RootViewController is showing in place of your detailViewCOntroller? it seems you're doing something bad... (maybe inverted viewControllers order in SplitViewController.viewControllers ?)

VinzzzBarto
Nope,As I said above, as soon as I rotate, it works fine. this is only on launch
Josh
A: 

You need to make sure to add your UISplitViewController's view to the UIWindow INSIDE the application:application didFinishLaunchingWithOptions: method of your app delegate (not later), or the split view won't rotate correctly initially.

Yup, thats where I am adding it. Still no dice. It works fine when you are holding the device, but if it is flat on its back, we have these issues.
Josh