I'm building a game in Swift 5 programmatically and want to navigate from the main menu to the game screen. Here is my code:
func handleButtonsTapped() {
playButton.addTarget(self, action: #selector(pushGameViewController), for: .touchUpInside)
}
And the selector to handle pushing the view controller when tapped:
@objc func pushGameViewController() {
let destinationVC = GameViewController()
navigationController?.pushViewController(destinationVC, animated: true)
}
When I tap the button in simulator nothing happens. I have handleButtonsTapped()
called in my viewDidLoad()
function as well.