Last active
March 13, 2016 21:12
-
-
Save pcperini/ea5c6b03aab09d3fcecd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContainedViewController: UIViewController { | |
weak var dataDelegate: FrameViewControllerDataDelegate? | |
override func willMoveToParentViewController(parent: UIViewController?) { | |
super.willMoveToParentViewController(parent) | |
self.dataDelegate = parent as? FrameViewControllerDataDelegate | |
} | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
self.dataDelegate?.reloadData() | |
} | |
} | |
extension ContainedViewController: FrameViewControllerDataType { | |
var titleText: String? { | |
return "Hello World" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FrameViewController: UIViewController { | |
@IBOutlet var titleLabel: UILabel! | |
var dataSource: FrameViewControllerDataType? | |
override func addChildViewController(childController: UIViewController) { | |
super.addChildViewController(childController) | |
self.dataSource = childController as? FrameViewControllerDataType | |
} | |
} | |
protocol FrameViewControllerDataType { | |
var titleText: String? { get } | |
var dataDelegate: FrameViewControllerDataDelegate? { get set } | |
} | |
protocol FrameViewControllerDataDelegate: class { | |
func reloadData() -> Void | |
} | |
extension FrameViewController: FrameViewControllerDataDelegate { | |
func reloadData() { | |
self.titleLabel.text = self.dataSource?.titleText | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment