Peyman
Peyman

Reputation: 3077

iOS app doesn't rotate when setting the RootViewController in FinishedLaunching

So the problem is--and this is new, this used to work in iOS 7-- when I comment out "FinishedLaunching", it rotates just fine but when I override this "FinishedLaunching" function to create the "window" myself, it fails to rotate. This is really strange. Any thoughts?

The reason I want to use FinishedLunching is because sometimes I want a different viewController to be the initial view controller.

Here is the code in my "FinishedLunching"

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

     UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];

     self.window.rootViewController = viewController;
     [self.window makeKeyAndVisible];

     return YES;
}

Upvotes: 0

Views: 113

Answers (1)

Alex
Alex

Reputation: 3971

The problem is that you are creating a new window with

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

when the AppDelegate one that it automatically sets up for you that is perfectly fine to use, just use self.window without alloc-initing a new one

Upvotes: 1

Related Questions