Add the same UIBarButtonItem to several UIViewControllers

青春壹個敷衍的年華 提交于 2019-12-11 05:28:07

问题


I want to add the same UIBarButtonItem to several UIViewControllers. I've done this previously by creating a parent UIViewController that manages to add the UIBarButtonItems in viewDidLoad. But now I have many view controllers that inherit from different view controllers, so if I follow the same strategy I should create a UIViewController subclass for each one of the different view controllers.

What I am actually doing is to configure the navigation bar buttons in my BaseViewController, the parent controller of all of the rest, depending on the flags I set when creating the child view controllers. With this solution the code only relies on one view controller, but I would like if there are more elegant options to achieve this.


回答1:


One of solutions is to use objective-c category. In this case, you will create common method for all UIViewControllers, that will create and configure UIBarButton



来源:https://stackoverflow.com/questions/21886073/add-the-same-uibarbuttonitem-to-several-uiviewcontrollers

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