Search code examples
uinavigationcontrolleruikituinavigationbaruinavigationitem

How to add global barButtonItems to custom UINavigationBar?


I am currently trying to create a custom UINavigationBar Subclass. What i want to achieve is that all custom navigationbars inside my app should have a couple of barbuttonitems in common. But it should still be possible to define left or .rightbarItems on the navigationItem in code.

What i tried so far is that subclassed the UINavigationBar and played around with all methods and delegate callbacks i could potentially use to change the navigationItem. There are methods like

setItems:animated:
setItems:
navigationBar:didPushitem etc.

.. which could be used to modify the navigationItem somehow. But there is no callback which can be used to change the item initially.

What i basically want to know is how it is possible to change navigationItem initially before it is being pushed ?


Solution

  • Solved it by myself using willShowViewController of the UINavigationControllerDelegateProtocol to modify the navigationItem