title: Setting text for IBOutlet labels in a custom UIView
body: <p>I have a custom UIView (MyView) object that gets loaded from a xib file. In the MyView.m I have a method that gets called in initWithCoder that does some initialization. This works for the most part, but I was trying to set the text in some IBOutlet label properties here, and it wasn't working, I realized because the properties were not initialized at this point.</p>
  
  <p>I tried setting the text of the outlets in the drawRect method, and it does work. But I think I read that implementing drawRect if you don't need to can cause some performance hits. My question is, where would the best place to set text of my IBOutlet label properties? (What I'm actually doing is setting it to localized versions of what's in the xib. I know about localized xib files, but I want to set the text in code.)</p>
  
  <hr>
  
  <p>Here is some code. Here is how I initialize the view in my view controller:</p>
  
  <pre><code>NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView"
                                                       owner:self
                                                     options:nil];
  _myView = [nibContents objectAtIndex:0];
  </code></pre>
  
  <p>Here is the initWithCoder method in MyView.m</p>
  
  <pre><code>- (id)initWithCoder:(NSCoder *)coder
  {
      self = [super initWithCoder:coder];
      if (self) {
          [self localizeLabels];
      }
      return self;
  }
  </code></pre>
  
  <p>And here is the localizeLabels method:</p>
  
  <pre><code>- (void)localizeLabels
  {
      self.powerPlant.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN1", nil);
      self.output.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN2", nil);
      self.capacity.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN3", nil);
  }
  </code></pre>
  
  <p>I have checked that these methods do get called using breakpoints, and that the properties are nil in the localizeLabels method.</p>