1

I am working with a team and our first two views in our workflow are created programmatically. We decided afterwards that we should use storyboards to facilitate some of the UI design. The initial view controller is LoginController, then it connects to UserProfileViewController. I want to design the UI for the second view in storyboards and have it connect to UserProfileViewController. How would I do this? It works if I make the view in the storyboard the initial view. If not it does not work.

Eric Agredo
  • 487
  • 1
  • 4
  • 13
  • 1
    Use a segue. If everything is created in UIViewController code, you simply need two *scenes* in IB, set each scene's identity to be each controller, create the segue (and name it) between them, and code for it. –  Jan 31 '17 at 00:58

1 Answers1

1

If you want to push to a Storyboard programatically here is how you do it in Swift.

//Swift 3.0
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.navigationController?.pushViewController(controller, animated: true)

The link below is another post on how to present a modal ViewController

//Swift 3.0
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)

Instantiate and Present a viewController in Swift

Community
  • 1
  • 1
monolith
  • 90
  • 1
  • 9
  • Your code presents the new view controller modally. The term "push" is used for adding a view controller to a navigation controller's stack, so that's the wrong term to use here. You should say "If you want create a view controller from a storyboard and present it modally, use the following code..." If you want to push it onto a navigation stack, use `pushViewController:animated:` – Duncan C Jan 31 '17 at 01:43
  • Your answer is now consistent, which is good. (voted.) It'd be better still if you offered both the push and the present variants as alternatives, especially since the link you provide shows a modal presentViewController, and your edited answer now provides a navigation controller push. – Duncan C Jan 31 '17 at 04:30