So I am still learning Swift and iOS. I have spent some time now searching the net. Also the Open AI chat, but nothing helps.
I have a login navigation setup, and if a user is logged in, I want to not show the login page again. I am using Firebase auth for this.
When I am creating a new user, and they succesfully sign up, I want them to navigate to the main page of the app.
I have this code in the sign up viewcontroller.
signUp(onSucces: {
// switch view
let vc = MainViewController()
self.navigationController?.setViewControllers([vc], animated: true)
}) { (errorMessage) in
ProgressHUD.showError(errorMessage)
}
and I have this in the new view controller I want to make root.
override func viewDidLoad() {
super.viewDidLoad()
}
When I successfully sign up, the screen just goes black. Also if I have a label, and I change the text of the label in the new view controller, I get a weird error. I know this might be stupid little error, but I can’t seem to find it, or know what to do.
4
Answers
It is unclear from your question whether the view controller is StoryBoard based or not.
If it is, then you need to use instantiateViewController(withIdentifier identifier: String) in order to initialize the view controller, instead of a simple init which is what you do at the moment.
If it isn’t storyboard based, then something is probably wrong with the view controller code, so it is recommended to post the entire code.
If you create a viewcontroller programmatically like you did
The vc’s background color is automatically will be
black
To make change to it , in your
MainViewController
‘sviewDidLoad
method , give a background colorWhat went wrong:
As per your code you are using UIKit and so to show any controller you have to instantiate the Storyboard controller like:
first of all, you have a problem regarding the Storyboard
Please mention the storyboard name from the project editor as well as you use below code
Please create one singleton class of appldelegate window properties.
`window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = MainViewController()
window?.makeKeyAndVisible()