title: Loading .xibs into a UIView
body: <p>I have a UIViewController with its own .xib, and I want to use a UISegmentedControl to display different information on the bottom half of the screen.  I created a UIView in the container's .xib and connected it to a UIView property called <code>detailView</code> in the container's UIViewController.</p>
  
  <p>I then created three .xib files in IB, one for the view that each segment needs to display in the <code>detailView</code> area.</p>
  
  <p>I'm now stuck because I don't know how to load and unload the appropriate .xib file into the <code>detailView</code> area.  Here's where I am:</p>
  
  <pre><code>- (void)segmentValueChanged:(id)sender {
      switch ([sender selectedSegmentIndex]) {
          case 0:
              // Unload whatever is in the detailView UIView and 
              // Load the AddressView.xib file into it
              break;
          case 1:
              // Unload whatever is in the detailView UIView and 
              // Load the ContactsView.xib file into it
              break;
          case 2:
              // Unload whatever is in the detailView UIView and 
              // Load the NotesView.xib file into it
              break;
          default:
              break;
      }
  }
  </code></pre>
  
  <p>So how do I fill in the blanks and unload/load the detailView UIView properly?</p>
  
  <p>Thanks!</p>
  
  <p>--UPDATE--</p>
  
  <p>The code in viewDidLoad is now:
      - (void)viewDidLoad {
          [super viewDidLoad];</p>
  
  <pre><code>    // Set the default detailView to be address since the default selectedSegmentIndex is 0.
      NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"AddressView" owner:self options:nil];
      // assuming the view is the only top-level object in the nib file (besides File's Owner and First Responder)
      UIView *nibView = [nibObjects objectAtIndex:0];
      self.detailView = nibView;
  
      self.detailContainerView.autoresizesSubviews = YES;
      [self.detailContainerView addSubview:self.detailView];
  
      NSLog(@"self.view is %@", self.view);
      NSLog(@"self.detailContainerView is %@",self.detailContainerView);
      NSLog(@"self.detailView is %@", self.detailView);
  }
  </code></pre>
  
  <p>And the debugger messages are:</p>
  
  <pre><code>self.view is UIView: 0x3a24d80; frame = (0 0; 320 460); autoresize = RM+BM; layer = CALayer: 0x3a35190
  self.detailContainerView is UIView: 0x3a1aea0; frame = (20 57; 280 339); autoresize = W+H; layer = CALayer: 0x3a36b80
  self.detailView is UIView: 0x3a24d80; frame = (0 0; 320 460); autoresize = RM+BM; layer = CALayer: 0x3a35190
  </code></pre>
  
  <p>Thanks!</p>