I have a view with a navbar and underneath that navbar is a segmented control with its own controller (BigViewController
). Underneath that are 3 overlapping container views, each with their own controller (FirstVC, SecondVC, ThirdVC
). In one of the container view controllers, I am trying to access the navbar to put a rightBarButtonItem
in. I've been trying a few different things but I can't get anything to work. I'm still new to this so I've been trying to work it out but I guess I don't fully understand it.
In FirstVC
(or any for that matter) I want to put a rightBarButtonItem
in the navbar. However (I think?) the navbar belongs to BigViewController
. I think this because I can set a rightBarButtonItem
in BigViewController
by using self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Sim Incoming", style: .Plain, target: self, action: #selector(simulate))
, but not in First/Second/ThirdVC
. I've tried adding a prefix BigViewController.
when in FirstVC
but that doesn't work. Can anyone help me out?
Try using the parentViewController
property in any of the container view controllers.