0

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;
}
Louis Tur
  • 1,303
  • 10
  • 16
Peyman
  • 3,059
  • 1
  • 33
  • 68
  • Hey any reason you are making a new window instead of using the default window of your app delegate? This should be set up for you already: self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; – Alex Jan 07 '15 at 20:19
  • 1
    I meant to say you don't need to alloc-init a new one, that may be your problem, not sure – Alex Jan 07 '15 at 20:25
  • @Alex yup it solved my problem. Thanks. I just followed http://stackoverflow.com/questions/10428629/programatically-set-the-initial-view-controller-using-storyboards. You should post this as an answer so I can flag it as answer. – Peyman Jan 07 '15 at 22:04

1 Answers1

1

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

Alex
  • 3,861
  • 5
  • 28
  • 44