title: Changing Views from UISegmentedControl
body: <p>I have a best practice type of question regarding Nibs and UISegmentedControls.</p>
  
  <p>I have a nib file which contains a UISegmentedControl with 3 buttons. Each of which displays a different view in the main part of the window when toggled.</p>
  
  <p>Everything is working fine but I suspect my approach is flawed and was wondering if someone could suggest the way I was "meant" to do it.</p>
  
  <p>Currently in the NIB I have 3 UIViews which are overlayed on top of one another and then in the .m file I modify each UIViews .hidden to hide and reveal the one I am interested in.</p>
  
  <pre><code>- (IBAction)segmentAction:(id)sender
  {
      if([sender selectedSegmentIndex] == 0)
      {
          [self.view1 setHidden:NO];
          [self.view2 setHidden:YES];
          [self.view3 setHidden:YES];
      }
      else if([sender selectedSegmentIndex] == 1)
      {
          [self.view1 setHidden:YES];
          [self.view2 setHidden:NO];
          [self.view3 setHidden:YES];
      }
      else if([sender selectedSegmentIndex] == 2)
      {
          [self.view1 setHidden:YES];
          [self.view2 setHidden:YES];
          [self.view3 setHidden:NO];
      }
  }
  </code></pre>
  
  <p>Everything "works" but the nib file is a pain to edit as you can't easily "turn off" the other UIViews so I invariably select the wrong element on the canvas. Also IB complains that: "This view overlaps one of its siblings" in the info dialog.</p>
  
  <p>What is the approach I should be taking given that I would like all of the views to be laid out in InterfaceBuilder. Should I have 4 nib files? If so how should I load them in when a segmentControl is pressed? Any sample code you can direct me to?</p>
  
  <p>thanks</p>