0

My rootViewController works and loads fine. However, when I call it using the present(viewControllerToPresent: UIViewController, animated: true, completion: nil) from another viewController I get nothing but a black screen.

I looked all over the stackOverflow but only found solutions for storyboard users. I am doing this programmatically

@objc func handleLogin() {
    print("LOGIN BUTTON TOUCHED")
    guard let email = emailTextField.text, let password = passwordTextField.text else {
        print("Form is not valid.")
        return
    }
    Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
        if error != nil {
            print(error!)
            return
        }
        let viewController = RootViewController()
   ***  self.present(viewController, animated: true, completion: nil)
        print("Logged in")            
    }
}
N. Der
  • 507
  • 4
  • 18

2 Answers2

1

There is nothing wrong with self.present(viewController, animated: true, completion: nil)

I think your RootViewController() is already presented. The black screen you see is might be the one without any data? I am not sure, will need your code for that class.

Another approach you can consider is to replace the real rootViewController from current uiWindow like this

@objc func handleLogin() {
  print("LOGIN BUTTON TOUCHED")
  guard let email = emailTextField.text, let password = passwordTextField.text else {
    print("Form is not valid.")
    return
  }

  Auth.auth().signIn(withEmail: email, password: password) { [weak self] (user, error) in
    guard let strongSelf = self else { return }
    guard error == nil else { return }
    guard let user = user else { return }

    UIApplication.shared.keyWindow?.rootViewController = RootViewController()
    print("Logged in")            
  }
}
0

you've created a new instance(RootViewController) and it must be black .. your not referring to your RootViewController