-1

I'm not sure exactly how to phrase the question, but after the user finishes onboarding and clicks on a button, I want to change view controllers from the Onboarding storyboard to the Main storyboard.

        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let vc = storyboard.instantiateViewController(withIdentifier: "Main")

        present(vc, animated: true)

the code above gives me a result like this:

enter image description here

How can I completely replace the view controller and not show it like a smaller view controller of the onboarding page?

Uditi
  • 19
  • 2
  • Here's a schematic implementation for the one time onboarding architecture: https://github.com/mattneub/RegistrationExample – matt Dec 24 '21 at 00:37

1 Answers1

-1

Asuming you are in a UIViewcontroller, you should use this code:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController      = storyBoard.instantiateViewController(withIdentifier:"ID_OF_YOUR_UIVIEW")
        self.navigationController?.pushViewController(resultViewController, animated: false)

Instead of:

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let vc = storyboard.instantiateViewController(withIdentifier: "Main")

        present(vc, animated: true)

OR you can create an extension into your AppDelegate like this:

extension UIViewController {
    
    func redirect(UIStoryboardName:String,viewId:String){
            let storyBoard : UIStoryboard = UIStoryboard(name: UIStoryboardName, bundle:nil)
            let resultViewController      = storyBoard.instantiateViewController(withIdentifier: viewId)
            self.navigationController?.pushViewController(resultViewController, animated: false)
        }
}

USAGE:

in your ViewController after users click on your button call like:

self.redirect(UIStoryboardName:"Main",viewId:"ViewControllerId")