I want to programmatically move from a viewController to another using Apple's new Swift language. I've googled and read through the docs, and I see how to use a single ViewController. Does anyone have an example or documentation on how to switch between View Controllers?
Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.
Well, in addition to that, Ctrl+dragging also helps set up segues. So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below.
I know that many developers have a single View Controller for every screenful of content, but actually the answer is 8. This is one of the things you can do to make your app more composable and decoupled: use child view controllers. It's a very simple, but powerful technique.
There are many ways to do this detailed in the class documentation for UIViewController
.
Example 1
Here is an example of using the -presentViewConroller:
method (assuming this code is written in a UIViewController
subclass):
var secondViewController = UIViewController() //create your second view controller.
self.presentViewController(secondViewController, true, NULL)
Example 2
This is how you would present the second UIViewController
via storyboards (again assuming this code is written in a UIViewController
subclass):
self.preformSegueWithIdentifier("segueIdentfier", self);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With