2

This is a "sort-of" question, that I am just hoping some astute individual can give me some guidance on.

I have an iOS project that has numerous screens (ViewControllers) that all share a top and bottom bar (an UIImageView with a button on each). I am using a storyboard because I want to be able to easily visualize the entire graph of screens.

Is there any way in Xcode 4.5 to make a sort of UI Template, or somehow subclass the "view" in IB so that whenever I make a new screen (VC) it inherits the top and bottom bars and the associated functionality?

I was hoping if I created a UIViewController subclass, put an IBOutlet for each ImageView and Button into it, and the associated IBAction for the two buttons, then subclassed it when making my VCs I would be able to link it all up, allowing me to only have to duplicate the visual elements on each screen. But alas, when I do that I get "not KVC-compliant" errors on the subclass (when linking it to the existing outlet and actions).

The other thought I had was to programmatically add the visual elements from a superclass, but then, for me, the problem is in IB I have to remember to account for the missing space at the top and bottom, which I will have to live with if that turns out to be the only option...

Is there some way to do this that I am not seeing or do I really have to code this all over and over for each screen?

Any insight/input/ideas greatly appreciated.

4
  • If I'm understanding you correctly, it sounds like your view controllers share some common views and behaviors in such a way that it might make sense to extract the tool bars etc. into a container-like view controller, and let it take care of the toolbars and the buttons and let your other view controllers manage presenting their specific content. Or am I way off? Sep 25, 2012 at 1:19
  • No, Carl, I think you have it... it is very much like that. My big problem with this approach is that I would have, on the storyboard, the entry screens (login and such) connected to a single VC, and then a bunch of dangling Views that would be the functional, subordinate views that would get swapped out into the container. This destroys the benefit of using the storyboard for visualizing the system. I know it is asking a lot, but I am hoping someone has some clever trick for managing this sort of thing, which cannot be all that uncommon, I would imagine.
    – Raconteur
    Sep 25, 2012 at 1:31
  • Ah, I see. I don't use story boards at all I'm afraid so I'm no help there. Another alternative is to use a nib just for the toolbars and everything, and in all your view controllers load that nib and add its content to the view hierarchy. Not sure if that would interfere with storyboards or not though. Sep 25, 2012 at 1:34
  • I think I am going to try making a superclass that provides the generic functionality, and programmatically adds the visual elements. Then I will just have to make my VCs in the storyboard small enough to fit the visible area that remains. Thanks for the comments!
    – Raconteur
    Oct 4, 2012 at 23:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.