0
votes

I have ViewController created using StoryBoards and I set it's class to be MyViewController.

MyViewController is class that inherits from UIViewController and have some UI elements. One of this elements is UIButton. I can programmatically add actions to this button as addTarget.

I want to to change view in NavigationController when button is clicked

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let newViewController = storyboard.instantiateViewController(withIdentifier: "newViewComtroller")
navigationController.pushViewController(newViewController, animated: true)

But nothing happens - why?

1

1 Answers

1
votes

Check in your storyboard if your view controller has an embeded Navigation Controller. If not, you can click in your view controller, go to "Editor" on XCode's menu, "Embed in", and choose "Navigation Controller". After that, your view controller will be associated with a navigation controller, and you should be able to use the method "pushViewController" properly.