Initializing custom UIView from XIB file
I know there have been a few [similar questions][1] asked about this, but I'm still unclear as to the proper design patterns for building hierarchical UIViews in the Interface Builder.  The basic requirements are:

 1. Code reuse - I have several view elements that are common across multiple views and would like to be able to have changes to the same XIB affect those uniformly.
 2. Interface Builder design - I find the layout easier to work with in the interface builder as opposed to written in code.
 3. Clean code base - I don't want to have a bunch of classes all trying to accomplish a simple task.

In attempting to just lay the views out in code, I have found it a tedious process to debug and deal with tweaking the view to how I want it.  But when reading [this post][2] about instantiating subviews from XIB files, it seems like there should be a better way to do it.  In that solution, one must create an XIB, then a .h/.m file to manage the outlets for that custom view, and then must also add a .h/.m file for the container for that view; only then does the container actually get placed as a subview of your master screen.

This seems like code bloat to me.  We have created 5 files all to deal with a simple subview with some outlets.  Is the container class that wraps the custom UIView really necessary?  I would like to be able to just throw a UIView subview into my XIB layout, designate its class as my subview, and then move on.

What is the best design pattern to use?  Is is really necessary to have the overhead (both computational and coding) of the extra container, or is there a way I don't know of to bypass that container and add the custom view with outlets directly as a subview within an XIB?

Thanks,
Chris


  [1]: http://stackoverflow.com/questions/10359858/loading-a-custom-uiview-from-a-xib-file-within-a-xib-for-a-viewcontroller-view
  [2]: http://stackoverflow.com/questions/10359858/loading-a-custom-uiview-from-a-xib-file-within-a-xib-for-a-viewcontroller-view
Initializing custom UIView from XIB file
===

I know there have been a few [similar questions][1] asked about this, but I'm still unclear as to the proper design patterns for building hierarchical UIViews in the Interface Builder.  The basic requirements are:

 1. Code reuse - I have several view elements that are common across multiple views and would like to be able to have changes to the same XIB affect those uniformly.
 2. Interface Builder design - I find the layout easier to work with in the interface builder as opposed to written in code.
 3. Clean code base - I don't want to have a bunch of classes all trying to accomplish a simple task.

In attempting to just lay the views out in code, I have found it a tedious process to debug and deal with tweaking the view to how I want it.  But when reading [this post][2] about instantiating subviews from XIB files, it seems like there should be a better way to do it.  In that solution, one must create an XIB, then a .h/.m file to manage the outlets for that custom view, and then must also add a .h/.m file for the container for that view; only then does the container actually get placed as a subview of your master screen.

This seems like code bloat to me.  We have created 5 files all to deal with a simple subview with some outlets.  Is the container class that wraps the custom UIView really necessary?  I would like to be able to just throw a UIView subview into my XIB layout, designate its class as my subview, and then move on.

What is the best design pattern to use?  Is is really necessary to have the overhead (both computational and coding) of the extra container, or is there a way I don't know of to bypass that container and add the custom view with outlets directly as a subview within an XIB?

Thanks,
Chris


  [1]: http://stackoverflow.com/questions/10359858/loading-a-custom-uiview-from-a-xib-file-within-a-xib-for-a-viewcontroller-view
  [2]: http://stackoverflow.com/questions/10359858/loading-a-custom-uiview-from-a-xib-file-within-a-xib-for-a-viewcontroller-view