0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I forgot about it! Is there any way that it can be done programmatically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.