I have a container view which performs a couple of segues inside based upon a users actions. I also have a top UIView that I would like to control from within the container view segue and set it's state.
I've tried to set a delegate to the home controller using a protocol and also the following approach:
if let parent = self.parent as? HomeController {
parent.handleTopBarState(state: .web)
}
What I would like to happen is when I'm on a specific view controller, set the parent view controller's top bar view's state.
Thanks.
If you have added child view controller then you can access simply with self.parent. To make sure put it in if let and cast
if let parent = self.parent as? ParentViewController {
parent.resetItemsCollectionView()
}
If you have embedded view controller on another view controller, you can message it's parent view controller with many ways.
var
with type of the parent in child, and assign the parent on prepare(for segue: UIStoryboardSegue, sender: Any?)
function, and call any public methods of the parent.prepare(for segue: UIStoryboardSegue, sender: Any?)
, and call protocol methods whenever you want.NotificationCenter
on child, and observe the notification on parent. Documentation of NotificationCenter
, here you can find a brief example of using it.Hope this helps!
PS: You can also observe properties of the child in the parent vc, if you want that way, I can explain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With