I
I
Ilya2016-03-02 20:36:52
Objective-C
Ilya, 2016-03-02 20:36:52

How to create transition between ViewController by condition?

Hello, I recently started learning Swift. And when I started writing my thesis on it, questions arose. I need to make a button transition from one ViewController (let's call it MainVC) to another ViewController (let's call it FirstVC) if the first Segment is selected on the Segmented Control. Or go to the third ViewController (let's call it SecondVC) if the second Segment is selected on the Segmented Control.
If it's quite simple to say - then how can I switch between different VCs using the same button, depending on where the checkmark is?
UPD:
This is how I call the second form, but alas, I get the error "Thread 1: signal SEGABRT":

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("MainGameVC") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2016-03-02
@Zubenko1703

A bunch of times the question of transitions between screens was raised
. What is the best way to transfer data between ViewControllers?
UPD.
1) If the controllers are in the same storyboard, then you can use self.storyboard
2) Check that your view controller really has this ID
3) Check that the current view controller is in the controller's navigation stack
4) Use self.navigationController.pushViewController(vc, animated: true)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question