title: How to set subview of UIView dynamically (iPhone)?
body: <p>I am surely doing something completely stupid here, hopefully someone can tell me what! In summary I would like to programmatically toggle a subview when a button (I'll use a segmented button) is clicked. It need not animate. Ideally I'd load the contents of these views from a nib.</p>
  
  <p>I am pushing a UIViewController subclass, initialised from a nib, on to a navigationController. This view controller &amp; it's "default" view display ok. This nib contains:</p>
  
  <pre><code>File's Owner [Class=my view controller subclass]
  First Responder
  View
  --Bar Segmented Control
  --View //this is the 'subview' whose content I want to toggle
  </code></pre>
  
  <p>Perhaps I've made a mistake with my IB outlets? They are hooked up as follows:</p>
  
  <pre><code>switchableView &lt;--&gt; View
  view &lt;--&gt; View
  </code></pre>
  
  <p>And where <code>switchableView</code> is declared:</p>
  
  <pre><code>IBOutlet UIView *switchableView;
  ...
  @property (nonatomic, retain)   UIView *switchableView;
  </code></pre>
  
  <p>I am stuck at replacing the contents of this UIView. First off, I just want to set it to a default when the view first comes to life. Once I've got that, swapping it to something else should be easy as I can already capture the event generated by the segmented button. Can someone please tell me what I am doing wrong?</p>
  
  <pre><code>- (void)loadView {
  NSLog(@"loadView invoked");
  [super loadView];
  UIView *view = [[UIView alloc] init];
  UILabel *label = [[UILabel alloc] init];
  label.text = @"Segment1";
  [view addSubview:label];
  [switchableView addSubview:view]; //this is what I can't work out
  [view release];
  [label release];    
  }
  </code></pre>
  
  <p>That method <em>is</em> invoked (as is <code>viewDidLoad</code>), but neither help. I guess that I am doing <code>[switchableView addSubview:view]</code> wrong. I've also tried <code>switchableView = view</code>, but a long time in the safety of Java and Perl makes me not 100% sure whether that is right to try or not!</p>
  
  <p>Here's hoping someone can set me straight. Thanks in advance,</p>
  
  <p>Paul</p>