title: Using multiple nib files with a single view controller?
body: <p><strong>Background</strong></p>
  
  <p>I'm using interface builder to create the UI for an app I'm working on. The app has a single screen that displays a series of buttons. Clicking on a button displays an associated view which overlays the buttons. Clicking another button hides the previous overlay view and displays another one.</p>
  
  <p>Too make managing the UI easier in IB I've decided to create multiple nib files for each sub view that is to appear when clicking the relevant button. I'm then loading the sub view's nib file in the view controller's <code>viewDidLoad</code> method using the <code>UINib</code> class.</p>
  
  <p>The idea behind this was to avoid having multiple views stacked on top of each other in a single nib file as this would be hard to manipulate in IB. I could have created all the views in code but this would require a lot of tedious coding as the layouts of each sub view are quite complex (with multiple child views).</p>
  
  <p>Example code loading a sub view from a nib file.</p>
  
  <pre><code>- (void)viewDidLoad
  {
      UINib *aSubViewNib = [UINib nibWithNibName:@"aSubView" bundle:nil];
      NSArray *bundleObjects = [aSubViewNib instantiateWithOwner:self options:nil];
  
      // get root view from bundle array
      UIView *aSubView = [bundleObjects objectAtIndex:0];
      [self.view addSubview:aSubView];
  ...
  </code></pre>
  
  <p>The code above is repeated for the other views. </p>
  
  <p>To summarise I have a single screen iPhone app that has layered views that are shown/hidden by clicking buttons. This is achieved with a single view controller with an associated nib file and a series of additional nib files for the sub views which are loaded in the view controller's viewDidLoad method.</p>
  
  <p><strong>Questions!</strong></p>
  
  <p>Sorry for the long introduction but I wanted to be very clear what it is I am doing.</p>
  
  <ul>
  <li>Is my approach bad or unusual?</li>
  <li>Are there any potential issues to doing it this way?</li>
  <li>What have other people done when they need a dynamic interface and
  still want to keep everything in Interface Builder?</li>
  </ul>
  
  <p><strong>Notes</strong></p>
  
  <p>Before anyone asks why don't I just display the sub views on a new screen and use the navigation bar, let me say that I have very good reasons and I do understand iOS UI guidelines. The above use case is not exactly my use case but it's one that clearly describes the problem without getting bogged down in my development app.</p>
  
  <p>Also I know I could have written all the sub views as code but each sub view has a complex layout of child views and it would be a lot of code and messing around to try and get them looking right.</p>
  
  <p><strong>Thanks in advance.</strong></p>