I have a modal view controller whose view comes from a XIB. I want it to have the same look and feel as the rest of my navigation based app, but it’s not a view that’s pushed to the navigation stack, it’s presented modally. I dragged a UINavigationBar in and made it an outlet, but it doesn’t have a title property to set. I have two fields that can bring up this modal view, and I want the title set differently depending on which one creates the modal view.
Share
UINavigationBar‘s manage a stack ofUINavigationItems much like aUINavigationControllermanager a stack ofUIViewControllers. To set what is visible directly, you should use eitherpushNavigationItem:animated:orsetItems:animated:using the navigationItem of the view controller you want the bar to reflect.eg:
The above code where you have a property
navigationBarwhich references the stand-alone navigation bar.If you don’t want to manage it yourself, you can do as mplappert suggested and nest your view controller (without a stand-alone
UINavigationBar) in aUINavigationControllerand present the navigation controller modally instead of your view controller.