xcode two view_controller move between them

0

Good I'm doing the test of having two view_controller one called Main and another view_2 , in each one there is a button and that serves as a navigation between them, but I fail to return.

In the first view controller , called main I have this code:

@IBAction func button_1(sender: AnyObject) {
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let ViewControllerDos = storyBoard.instantiateViewControllerWithIdentifier("view_2")
    self.presentViewController(ViewControllerDos, animated: true, completion: nil)  
}

And in second view controller , called view_2 I have this:

@IBAction func button_2(sender: AnyObject) {
    let storyBoard1 : UIStoryboard = UIStoryboard(name: "view_2", bundle: nil)
    let ViewControllerDos1 = storyBoard1.instantiateViewControllerWithIdentifier("Main")
    self.presentViewController(ViewControllerDos1, animated: true, completion: nil)
}

But I get an error when I press the button in the second, what am I doing wrong?

Thank you.

    
asked by Juan Jose Alarcon 05.07.2016 в 23:45
source

1 answer

1

The problem is that you do not understand what the flow is, which is why I strongly advise against using Storyboards since they only interfere with learning.

Notice that in the first you do a presentViewController and therefore what you are doing is to show a ViewController of modal form. Well, to go back to what you should do is close that ViewController using the following function:

self.dismissViewControllerAnimated(true, completion: nil)

With this, when presented in a modal form, it will be closed and you will return to ViewController that presented it.

    
answered by 06.07.2016 в 00:25