Reputation: 117
I'm new in Swift and I've this issue: I load the main storyboard and if the user is nil then I load another storyboard with other scenes. For doing this I run this code:
override func viewDidAppear(_ animated: Bool) {
if (true) {
let loginScene = UIStoryboard(name: "NilUser", bundle: nil).instantiateViewController(withIdentifier: "loginScene") as! LoginController
loginScene.modalPresentationStyle = .fullScreen
show(loginScene, sender: nil)
}
}
I know that the if statement is always true, I want it at the moment. I also checked if the login scene was the initial one, but even like this the navigation bar doesn't show itself. The problem is that now ini the login scene I don't see the navigation bar and I don't get why. What can I do? If you need more explanations I'll give you. Thanks!
Upvotes: 0
Views: 763
Reputation: 764
As far as I understand
self.navigationController?.pushViewController(loginScene, animated:true)
won't work since self.navigationController? is nil
by calling
let loginScene = UIStoryboard(name: "NilUser", bundle: nil).instantiateViewController(withIdentifier: "loginScene") as! LoginController
you instantiate your LoginController directly without it's UINavigationController therefore you should make the UINavigationController the initial ViewController and try
let storyboard = UIStoryboard(name: "NilUser", bundle: nil)
guard let navigationController = storyboard.instantiateInitialViewController() else {
// initial UINavigationController not found
return
}
navigationController.modalPresentationStyle = .fullScreen
show(navigationController, sender: nil)
If I'm wrong I might have missed something in your setup.
Upvotes: 1
Reputation: 25
try this
let loginScene = UIStoryboard(name: "NilUser", bundle: nil).instantiateViewController(withIdentifier: "loginScene") as! LoginController
self.navigationController?.pushViewController(loginScene, animated:true)
Upvotes: 0