I have an application that uses a UITabBarController as its outer container. Each tab uses a UINavigationController for its root view controller. I employ a multi-button toolbar as the navigation bar’s right bar button. Some of these toolbar buttons are universal to the application; some pertain to individual tabs.
My instinct is to create a base view controller class with all universal toolbar construction and implementation code, then have each of my root view controllers inherit from this base class. If they want to add additional buttons to the toolbar, they simply need to override the toolbar construction method (where I’ll centralize the construction of the tool bar), and add the implementation code for the additional buttons.
Sounds good in theory, but since I’m new to Objective-C, I welcome any additional input/advice from more experienced developers.
If you have a enough reusable code in your “toolbar construction and implementation ” to motivate you to implement a base class and reuse it on your child classes, then it actually sounds like a good solutions.
One thing that you should analyze is which class would you extend: UIViewController or UIToolBar.
If you just want a custom reusable toolbar that only changes some visual properties (like the label of a the left button, or let the right button visible or not, etc..), maybe the best approach is to implement a base class that extends from UIToolBar, and then use it in your view controllers.
But if you have a considerable complex logic handling actions from the buttons of the toolbar, or any “heavy code” beyond simple visual property settings, the creation of a base class that extends UIViewController sounds like a better approach.
The better choise is up to you and to what you want to implement/reuse.
Good luck!