That's all, my question is the following: SWIFT - Hide the view container using the button in the ViewContainer
In short, I have a UIViewController (Main) that contains a "SHOW" button and a container. In the container view ("containerView") there is one button "HIDE". Initially, the View container is hidden, and when the "SHOW" button is pressed, it is displayed. Things are good. I want to use the delegate in such a way that when I click the HIDE button, the container will be hidden.
I understand all the delegate stuff, EXCEPT, how does the View container become a viewController so that I can assign Main to the delegate?
The view of the container is a UIView that (somehow) points to / contains the view controller, but I cannot determine how to reference it.
import UIKit
class MainViewController: UIViewController,dismissPickerViewDelegate {
@IBOutlet weak var pickerContainerView: containerView!
@IBOutlet weak var showButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
pickerContainerView.hidden = true
}
@IBAction func showButtonTapped(sender: AnyObject) {
println("+Show")
pickerContainerView.hidden = false
println("-Show")
}
func dismissPicker()
{
println("+dismissPicker")
println("-dismissPicker")
}
}
import UIKit
protocol dismissPickerViewDelegate {
func dismissPicker()
}
class pickerViewController: UIViewController {
var delegate : dismissPickerViewDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBOutlet weak var hideButton: UIButton!
@IBAction func hideButtonTapped(sender: AnyObject) {
println("+hideButtonTapped")
delegate?.dismissPicker()
println("-hideButtonTapped")
}
}
Exit: + Show -Show + hideButtonTapped -hideButtonTapped
TIA,
source
share