Reputation: 45
As I want to have more control over actions of when someone could press a button for going to another view controller, I tried to step away from the navigation controller system.
At the moment, as I'm still just a starter in Xcode I'm struggling with opening a view controller and closing it.
I tried to open it with this code:
@IBAction func didTapGame(){
let vc = storyboard?.instantiateViewController(identifier: "Game_VC") as! Game_ViewController
present(vc, animated: true)
}
and on the iPhones it seemed legit, but on the iPad it appeared modally as a screen on top of the homescreen of the app and too small so you could just tap it away on the side.
How do you properly present a view controller in code in storyboard and how do you close it again with a backbutton as I tried the backbutton the same way, but it just added a new homescreen on top of everything which isn't desirable of course, Thanks!
Upvotes: 0
Views: 265
Reputation: 197
It is difficult to answers without more context, but if you have a UINavigationController you can try this:
self?.navigationController?.pushViewController(viewController: vc, animated: true)
Upvotes: 0