function not transfer to vc

I made an extension to UIViewController and inside i have function I use several times:

extension UIViewController {
  func transitionToHomeVC() {
    let homeViewController = self.storyboard?.instantiateViewController(withIdentifier: NameConstants.StoryBoard.homeViewController) as? HomeViewController

    self.view.window?.rootViewController = homeViewController
    self.view.window?.makeKeyAndVisible()
  }
}

And I have a registration button and as soon as you click if the information was received and correct and etc ... then he has to move me at the to the HomeViewController screen and he does not do it. He does all the actions but does not pass to screen.

@IBAction func signUpTapped(_ sender: Any) {
    // Validate the fields
    let error = validDataFields()
    if error != nil {
      // There's something wrong with the fields, show error message
      Service.showError(vc: self, message: error!)
    }
    else {
      // Create cleaned versions of the data
      let fireName = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let lastName = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
    
      // Create the user
      Auth.auth().createUser(withEmail: email, password: password) { resulte, err in
        // Check for errors
        if err != nil {
          // There was an error creating the user
          Service.showError(vc: self, message: "Error creating user \n make sure you enter: \n current email")
        }
        else {
          // User was created successfully, now store the first name and last name
          let db = Firestore.firestore()
          db.collection("users").addDocument(data: ["firstName":fireName,"lastName":lastName, "uid": resulte!.user.uid]) { error in
            if error != nil {
              // Show error message
              Service.showError(vc: self, message: " Error saving user Data")
            }
          }
          self.transitionToHomeVC()
        }
      }
    }
  }
   

why it not move to homeViewController?

I would try to call self.transitionToHomeVC() in the main thread.

   DispatchQueue.main.async {             self.transitionToHomeVC()           }

not working..

Is it iOS or MacOS app ?

Could you add some print statement to log:

  func transitionToHomeVC() {
    let homeViewController = self.storyboard?.instantiateViewController(withIdentifier: NameConstants.StoryBoard.homeViewController) as? HomeViewController
    print("identifier", NameConstants.StoryBoard.homeViewController)
    print("homeViewController", homeViewController)
    print("self.view.window", self.view.window)

    self.view.window?.rootViewController = homeViewController
    self.view.window?.makeKeyAndVisible()
  }

And tell what you get ?

Why do you change the rootViewController, and not just call

sel.present(homeViewController, animated: true, completion: nil)

it IOS

on console it print:

identifier HomeVC
homeViewController nil
self.view.window nil

whose view is not in the window hierarchy.

You didn't answer my questions:

  • Is it iOS or MacOS?
  • Why do you change the rootViewController, and not just call
self.present(homeViewController, animated: true, completion: nil)

Problem is

homeViewController nil
self.view.window nil. 

You have to find why.

Are you sure the HomeViewController identifier is HomeVC (take care of uppercase).

  1. it for IOS
  2. I tried it and it also does not work,

It prints me at the console: whose view is not in the hierarchy window.

To the third question: Yes I am sure and I too made sure it was HomeVC (And I also took care of capital letters)

Could u you post (for instance on We Transfer) an example code ?

function not transfer to vc
 
 
Q