Setting the Windows key rootViewController not working in iOS8

In my application, I need a user to log in and log out. When I want the user to log out, I will delete their credentials, and then:

ZSSLogin *login = [self.storyboard instantiateViewControllerWithIdentifier:@"ZSSLogin"];
[[UIApplication sharedApplication].keyWindow setRootViewController:[[UINavigationController alloc] initWithRootViewController:login]];

It is supposed to replace the current rootViewController(tabBarController) with an input viewController.

On iOS7, this works correctly. But in iOS8, it will show the VC login for a second of a second, but then it will go back to tabBarController as if nothing had happened.

Any ideas on what's going on?

+4
source share
3 answers

: VC , SplitViewController iOS8, iOS7 .

, AlertView , rootViewController AlertView, .

:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
...

    // Added a delay to avoid an iOS8 bug, where setting rootViewControler doesn't work after dismissing an AlertView. (For some reason dispatch_after isn't working here)
    [self performSelector:@selector(logout) withObject:nil afterDelay:0.5];
...

, iOS8 Window rootViewController AlertView, rootViewController rootViewController AlertView. , rootViewController , , . , rootViewController, . , .

+3

. AlertView. AlertView Delegate : alertView:didDismissWithButtonIndex: Setting RootViewController.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0){
        // change Application.keyWindow.rootViewController
    }
}
+2

, iOS 8. iOS 8 rootViewController . , - rootViewController.

Apple also says: “The root view controller provides a view of the contents of the window. Assigning a view controller to this property (programmatically or using Interface Builder) sets the view manager view as a view of the contents of the window. There is an existing view hierarchy in the window, old views are deleted before new ones will be installed. "

for (UIView * subView in self.window.rootViewController.view.subviews) {
    [subView removeFromSuperview];
}
0
source

All Articles