The app I’m building needs to show a shared custom UIToolbar for multiple views (and their subviews) within a UITabBarController framework. The contents of the custom toolbar are the same across all the views. I’d like to be able to design the custom toolbar as a xib and handle UI events from its own controller class (I’m assuming I can subclass UIToolbar to do so?). That way I could define IBOutlet & IBAction items, etc. Then I could associate this custom toolbar with each of the UITabBarController views (and their subviews). But I’m having trouble finding out whether that’s possible – and if so, how to do it.
In particular, I want to be able to push new views onto UINavigationController view stacks which are each associated with parent UITabBarController tabs. So, to summarize, I want a:
- custom toolbar
- shared by multiple views
- which are managed by multiple navigation controllers
- and the navigation controllers are associated with different tabs of a parent tab bar controller
The tab bar controller itself is launched modally, though I don’t believe that’s relevant.
Anyway, the tab bar controller is working, as are its child navigation controllers. I’m just having a little trouble figuring out how to persist the shared toolbar to the various subviews. I’d settle for a good clean way of implementing programmatically… though I’d prefer the flexibility of keeping the toolbar’s visual design in a xib.
Anyone have any suggestions
I believe I have the “answer”… and it’s so simple, I’m rather embarrassed that it didn’t occur to me before now. Create a custom subclass of UIViewController, within which you set the attributes of the UINavigationController’s toolbar (set as enabled from within the xib in IB). Then, from whichever other views you want that toolbar included, you just subclass that class. In my case, I named a ChallengeToolbar subclass of UIViewController, then I did this:
… within the viewDidLoad method. Then, from any view in which I want my toolbar to appear I simply set up the view’s controller class to subclass my ChallengeToolbar class instead of UIViewController. DUH!