Swift - Load next view controller if already registered

585 views Asked by At

When I run my app if the user is already registered(checking from the local database) I want to load a different ViewController. It is working but I see the previous screen for a split second and want to get rid of that. If I put the following code in the viewWillAppear or viewDidLoad it does not work. When I put it in ViewDidAppear it works and loads the next screen. How can I do this without seeing the screen for a split second?

This works but I see the previous screen for a split second.

   override func viewDidAppear(_ animated: Bool) {

    if(userInfo.Confirmed == "Yes") {

        performSegue(withIdentifier: "skipRegistration", sender: self)

    }

}

This does not work:

override func viewWillAppear(_ animated: Bool) {

    if(userInfo.Confirmed == "Yes") {

        performSegue(withIdentifier: "skipRegistration", sender: self)

    }
}

And this does not work:

override func viewDidAppear(_ animated: Bool) {

    if(userInfo.Confirmed == "Yes") {

        performSegue(withIdentifier: "skipRegistration", sender: 

self)

    }

}

Thanks!

You can do this code in appdelegate in appLaunch method and push your viewcontroller two time with no animation

NOTE Maintain your viewController stack properly.

Not understanding how to push the viewController.

I have the code inserted into appDelegate and I am trying to call the correct Controller to take over but can’t seem to find it. I have a tab bar controller and I have a navigation controller. It goes like this.

A registered user should skip to first screen of the app.

Not registered user gets these pages:

registration Screen

registration1 Screen

registration2 Screen

Agreement: Screen -> taps on accept agreement button then goes to:

Agreement segue -> (beginApp segue) to tab bar controller then goes to

Navigation Controller -> myFirst Screen of the App!

Everything is working but I need to skip to the first screen of the App.

I’ve tried using this sample code but can’t figure it out.

let navVC: UINavigationController =  rootView.viewControllers![4] as! UINavigationController


let vc = navVC.topViewController as! MoreTableViewController

I hope this makes sense!

2

There are 2 answers

0
Grumpy On

This is working!

// This works to load my tab bar controller and it works!
        let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController : UITabBarController = mainStoryboard.instantiateViewController(withIdentifier: "startHere") as! UITabBarController
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = initialViewController
        self.window?.makeKeyAndVisible()
0
dahiya_boy On

You can do this code in appdelegate in appLaunch method and push your viewcontroller two time with no animation

NOTE Maintain your viewController stack properly.