using UINavigationBar without UINavigationController

丶灬走出姿态 提交于 2019-11-30 13:48:22

The answer, if anyone's interested, is in the class reference of UINavigationBar.

When you use a navigation bar as a standalone object, you are responsible for providing its contents. Unlike other types of views, you do not add subviews to a navigation bar directly. Instead, you use a navigation item (an instance of the UINavigationItem class) to specify what buttons or custom views you want displayed. A navigation item has properties for specifying views on the left, right, and center of the navigation bar and for specifying a custom prompt string.

In short, use a UINavigationItem and apply it by "pushNavigationItem" on the UINavigationBar.

I created a subclass of UINavigationBar called StaticNavigationBar which I can then load with any state by putting the appropriate UINavigationItem's on it. Thanks for all your answers people.

You can have that UINavigationBar as an outlet and then you can manupulate it as you want. So you don't have to refer to somebody's navigation item. It'll be an independent (sort of) object on your view.

If you dont want the navigationbar as-is youll have to roll your own. if youre ok with the built in animations for pushing and popping items(dont confuse with push/pop of viewcontrollers) to the bar you would then set your UINavigationBarDelegate and use its methods for controlling how things push/pop, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!