Home > Software design >  Setting up a ViewController via url and show it as a popup
Setting up a ViewController via url and show it as a popup

Time:02-14

I currently have a method that I use to setup a new ViewController

func setRootView(viewController vc: UIViewController){
    UIApplication.shared.windows.first?.rootViewController = vc
    UIApplication.shared.windows.first?.makeKeyAndVisible()
}

How can I modify the presentation that the ViewController will show over the other screen like presentation style not modally ?

That is the function that gets called after the button is pressed and the view should change:

func moveToNextVC(isLogin: Bool){
    if self.checkNetworkConnection(){
        let vc = HomeVC(nibName: "HomeVC", bundle: nil)
        if isLogin{
            vc.modalPresentationStyle = .automatic
            vc.url = loginLink
            
        }else{
            vc.modalPresentationStyle = .automatic
            vc.url = signupLink
            
        }
        setRootView(viewController: vc)
    }
    else{
        showAlert("Alert!", message: "Please check your internet connection, then try again.")
    }
}

CodePudding user response:

Per Shawn Frank's comment:

Instead of doing this UIApplication.shared.windows.first?.rootViewController = vc, I would do present(vc, animated: true)

This solved the problem.

  • Related