1

I have a very simple app with a UIViewController called Outer. I put a container on that controller and inside of this container I embed another UIViewController called Inner.

By default Inner is hidden and Outer has a button that - when user presses it - brings on screen Inner (by changing its property hidden to false).

Since I'm passing some data from Outer to Inner, this is my code so far:

Outer.swift:

class Outer: UIViewController, ContainerToMaster {

    var containerViewController: Inner?

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "requestDetailsSegue" {
            containerViewController = segue.destinationViewController as? Inner
            containerViewController!.containerToMaster = self
        }
    }

    @IBAction func openInnerButtonAction(sender: AnyObject) {
        containerViewController?.changeLabel(description)
        inner.hidden = false
    }
}      

Inner.swift:

protocol ContainerToMaster {
    func changeLabel(text:String)
}

class Inner: UIViewController {

    @IBOutlet weak var eventDescr: UILabel!

    var containerToMaster:ContainerToMaster?

    func changeLabel(description: String) {
        eventDescr.text = description
    }

}

Now I want to add a button to the Inner panel that closes it after user presses it. What is the best way to do it?

user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

1

An unwind segue (aka exit segue) can be used to navigate back through push, modal or popover segues. Click here for more.

Community
  • 1
  • 1
Kemal Can Kaynak
  • 1,638
  • 14
  • 26
  • You should flag this question as a duplicate if you feel it is such. – JAL Mar 09 '16 at 15:41
  • 1
    Guys, I didn't know it is a duplicate, I couldn't find anything about it on Stack and that's why I asked this question. Kemal's answer was useful for me, I used the answer pointed by him and that solved my question. I will mark it as a correct answer, but if you feel obligated, feel free to mark my question as a duplicate. Regards – user3766930 Mar 09 '16 at 15:50