Reputation: 2157
I have such logic in my app:
I would like to move from ViewController to HomeScreen after 200 response from server, and in any other cases it will be done programmatically. I know about segue which can be attached to pressing button, but when I use segue and press login btn without text in fields I also move to Home Screen that is why I think that segue can't be used in such situation (I can be wrong), so I added id for Home Screen and added such code for pressing btn:
let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "homeScr") as? UITabBarController
self.navigationController?.pushViewController(vc!, animated: true)
and when I press this button noting happens. What I did wrong and how to solve this problem?
Upvotes: 0
Views: 694
Reputation: 2188
The controller you push cannot be a Tabbarcontroller according to apple documentation.
The view controller to push onto the stack. This object cannot be a tab bar controller.
Edit: As alternative this could be a solution:
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "mainApp") as! UITabBarController
nextViewController.modalPresentationStyle = .fullScreen
self.present(nextViewController, animated:true, completion:nil)
Upvotes: 1
Reputation: 780
In your appDelegate, add property:
final var window: UIWindow?
Open main like this in your Login view controller
func openMain() {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier:
"mainApp") as! UITabBarController
let window = UIApplication.shared.delegate!.window!!
window.rootViewController = nil
window.rootViewController = nextViewController
UIView.transition(with: window, duration: 0.4, options: [.transitionCrossDissolve], animations: nil, completion: nil)
}
Upvotes: 1