title: iOS loadNibNamed confusion, what is best practice?
body: <p>I'm familiar with most of the process of creating an XIB for my own UIView subclass, but not everything is working properly for me - it's mostly to do with the IBOutlets linking up. I can get them to work in what seems like a roundabout way.</p>
  
  <p>My setup is this:</p>
  
  <ul>
  <li>I have MyClass.h and MyClass.m. They have IBOutlets for a UIView (called view) and a UILabel (called myLabel). I added the 'view' property because some examples online seemed to suggest that you need this, and it actually solved an issue where I was getting a crash because it couldn't find the view property, I guess not even in the UIView parent class.</li>
  <li>I have an XIB file called MyClass.xib, and its File's Owner custom class is MyClass, which prefilled correctly after my .h and .m for that class existed.</li>
  </ul>
  
  <p>My init method is where I'm having issues.</p>
  
  <p>I tried to use the NSBundle mainBundle's 'loadNibNamed' method and set the owner to 'self', hoping that I'd be creating an instance of the view and it'd automatically get its outlets matched to the ones in my class (I know how to do this and I'm careful with it). I then thought I'd want to make 'self' equal to the subview at index 0 in that nib, rather than doing</p>
  
  <pre><code>self = [super init];
  </code></pre>
  
  <p>or anything like that.</p>
  
  <p>I sense that I'm doing things wrong here, but examples online have had similar things going on in the init method, but they assign that subview 0 to the view property and add it as a child - but is that not then a total of two MyClass instances? One essentially unlinked to IBOutlets, containing the child MyClass instantiated via loadNibNamed? Or at best, is it not a MyClass instance with an extra intermediary UIView containing all the IBOutlets I originally wanted as direct children of MyClass? That poses a slight annoyance when it comes to doing things like instanceOfMyClass.frame.size.width, as it returns 0, when the child UIView that's been introduced returns the real frame size I was looking for.</p>
  
  <p>Is the thing I'm doing wrong that I'm messing with loadNibNamed inside an init method? Should I be doing something more like this?</p>
  
  <pre><code>MyClass *instance = [[MyClass alloc] init];
  [[NSBundle mainBundle] loadNibNamed:@"MyClass" owner:instance options:nil];  
  </code></pre>
  
  <p>Or like this?</p>
  
  <pre><code>MyClass *instance = [[[NSBundle mainBundle] loadNibNamed:@"MyClass" owner:nil options:nil] objectAtIndex:0]; 
  </code></pre>
  
  <p>Thanks in advance for any assitance. </p>