Adding buttons to the titleview of NavigationBar without having to repeat code

主宰稳场 提交于 2019-12-04 13:29:38

I'd recommend just putting the above code in a UIViewController category (or a UIViewController subclass if you can subclass all your view controllers from a single root). Then in viewDidAppear, just call the above code (or put that in the superclass's viewDidAppear). I think that subclassing UINavigationBar is going to be more trouble than it's worth.

If you really want to avoid recreating the buttons (probably no reason to do so, but if it's important to you for some reason), you can wire the buttons to some singleton object rather than pointing them at self. The singleton could either handle the response directly, forward the message to the active view controller, or post a notification that the active view controller could listen for.

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