简体   繁体   中英

iOS app crashing after setting UIWindow rootViewController in iOS 9

My app was working great until running it on iOS 9.

In the AppDelegate, I check whether the user is logged in or not. If they're not logged in, I send them to the login screen with the following line:

self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"Login"];

After the user logs in, I attempt to send them to the main app with the following line:

self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"Tabs"];

This worked in iOS 8, but now it crashes the app. And it's a bad crash. The whole device has to reboot (although it's a very quick one, so I think it's more like a SpringBoard reboot or something).

I'm seriously at a loss as to why the first line works and the second doesn't. Any help is much appreciated!

EDIT

I ended up recreating the entire UIViewController flow that was crashing and it works fine now. As far as I can tell it was some strange bug in the new Xcode. Not considering this an answer, so if anyone has a true answer then feel free to share it.

Not sure why, but this works for me in iOS9. It might be that you're trying to do this already in the AppDelegate before the window has been properly loaded?

I've got a first ViewController in the storyboard and does this redirecting there instead.

UIViewController *viewController = [[UIStoryboard storyboardWithName:@"Storyboard"
                                                          bundle: nil] instantiateViewControllerWithIdentifier:@"viewController"];

[[[[UIApplication sharedApplication] delegate] window] setRootViewController:viewController];

The code to set the root view controller works in iOS9 without issues.

[[[[UIApplication sharedApplication] delegate] window] setRootViewController:viewController];

If you get a crash in that line, it surely means that the viewController initialization logic or any of its subviews are throwing at some point.

Problem is that working in the simulator the app will crash with no errors in the output. Best thing to do here is setting a breakpoint in the viewController logic (ie: viewDidLoad ) and check what line is causing the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM