title: IB and UIView. What is the correct way to load a view hierarchy from a nib?
body: <p>Can someone please school me on the proper way to load a view hierarchy from a nib file. I am using the loaded view as a template to stamp out a family of views and the current approach I am using is subtly broken. I don't appear to be copy-ing or retain-ing when I should be. Here's the relevant code:</p>
  
  <pre><code>// pageSet is a list of view tag numbers I'll be using
  for (NSNumber *n in pageSet) {
  
      NSUInteger viewTag = [n integerValue];
  
      // Ingest the nib. Should there be a copy or retain here?
      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RandomStripe" owner:self options:nil];
  
      // Pull the view from the nib. Should there be a copy or retain here?
      MyView *view = (MyView *)[topLevelObjects objectAtIndex:0];
  
      // The view has a label as it's subview
      UILabel *pageNumberLabel = [view.subviews objectAtIndex:0];
      pageNumberLabel.text     = [NSString stringWithFormat:@"%d", viewTag];
  
      CGFloat xOffset = ((float) viewTag) * self.scrollView.bounds.size.width;
  
      view.frame = CGRectMake(xOffset, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
      view.tag = viewTag;
  
      // Insert the view as a child of my containerView
      [self.containerView addSubview:view];
  
  } // for (pageSet)
  </code></pre>
  
  <p>This has be making my head hurt for while now? </p>
  
  <p>Cheers,
  Doug</p>