1

I am looking for a way to get my ToolBar in all my ViewControllers. Copying and pasting it doesn't seem like a good idea for when I make changes. I prefer to use storyboarding to keep my code clean.

evenwerk
  • 947
  • 1
  • 12
  • 28
  • What will the toolbar do on different screens? Will it have any buttons or information for display? – Evgenii Aug 02 '15 at 12:14
  • I think you need custom UIToolBar. You can google how to do that. Take into accout that you must be careful with delegation (`self.delegate = self`). Sometimes it can lead to infinite loop. At least in `Objective-C`. – Bogdan Bogdanov Aug 02 '15 at 12:14

2 Answers2

1

Just to be clear: You want multiple copies of the same toolbar, not a single toolbar that exists in multiple places. (View objects can't exist in more than one superview.)

I suggest defining your toolbar in an XIB file and then loading it from the XIB in each view controller that needs it. That way it's only defined in one place.

It's perfectly OK to load a view from an XIB in an app that primarily uses storyboards. You can use any combination of the 2 techniques. XIBs make it possible to load a view instead of a view controller scene.

See this SO post for an explanation of how to load a view object (not a view controller, a view) from an XIB:

iPhone - Load a UIView from a nib file?

Community
  • 1
  • 1
Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

I found this tutorial. Create an IBDesignable UIView subclass with code from an XIB file in Xcode 6

evenwerk
  • 947
  • 1
  • 12
  • 28