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?