John Difool
John Difool

Reputation: 5722

Transition from one viewcontroller to the next can't happen before first vc is displayed?

The logic goes like this:

The app delegate triggers the main viewcontroller (UIViewController, nothing fancy). code checks if we need to go to a different viewcontroller without displaying the current one. I use the code:

    let vc = storyboard!.instantiateViewControllerWithIdentifier("NextViewController")
    self.presentViewController(vc, animated: true, completion: nil)

I can get the right behavior in viewDidAppear which is too late because we are already showing the content. Moving the code in viewWillAppear complains about the fact that the vc is not in the view hierarchy yet.

What is the best approach? Should I start using a navigation controller?

Upvotes: 0

Views: 45

Answers (2)

jannemecek
jannemecek

Reputation: 31

If you decide to use a UINavigationController you can perform a check in viewDidLoad: method of the first VC and perform a segue without animation to the next view controller.

Such segue would be done like this this

.h:

#import <UIKit/UIKit.h>

@interface PushNoAnimationSegue : UIStoryboardSegue

@end

.m:

#import "PushNoAnimationSegue.h"

@implementation PushNoAnimationSegue

- (void)perform{
    [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
}

@end

Upvotes: 0

Antoine Garcia
Antoine Garcia

Reputation: 143

Have you try to do your check in your app delegate and do something like this ? :

let vc = storyboard!.instantiateViewControllerWithIdentifier("NextViewController")
self.window.setRootViewController(vc)

Upvotes: 1

Related Questions