Question

I have a login view that checks to see if there are default settings, then syncs data. If there are no default settings, the view waits for the user to login. if there are settings and the data syncs correctly, it should switch to my split view.

The code works if the user enters their login information. It syncs the data, then switches the view. If the user is already logged in, it hits the function and doesnt switch the view.

Here is the code being called by both paths:

-(void)redirect{
    NSLog(@"Redirect@");
    UISplitViewController *split = [self.storyboard instantiateViewControllerWithIdentifier:@"orders_split"];
    [self.view.window setRootViewController:split];
}

"Redirect@" shows in the log on the initial load if the user has already logged in once. I have confirmed that there are no sync errors, it hits the function but does not perform the switch.

I am moving from a standard view with nav controller to a splitview, so I cannot use a manual segue trigger.

Was it helpful?

Solution

try to use app delegate:

UISplitViewController *split = [self.storyboard instantiateViewControllerWithIdentifier:@"orders_split"];
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = split;

in my projects I do it with animation:

+(void)setRootController:(UIViewController*)controller
              storyboard:(UIStoryboard*)storyboard{

            MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

            [UIView
             transitionWithView:appDelegate.window
             duration:0.5
             options:UIViewAnimationOptionTransitionCrossDissolve
             animations:^(void) {
                 BOOL oldState = [UIView areAnimationsEnabled];

                 [UIView setAnimationsEnabled:NO];

                 appDelegate.window.rootViewController = controller;

                 [UIView setAnimationsEnabled:oldState];
             }
             completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top