title: Styling custom UITableViewCell in initWithCoder: not working
body: <p>I have some issues with a custom UITableViewCell and how to manage things using storyboards. When I put the styling code in <code>initWithCoder:</code> it doesn't work but if I put it in <code>tableView: cellForRowAtIndexPath:</code> it works. In storyboard I have a prototype cell with its class attribute set to my UITableViewCell custom class. Now the code in <code>initWithCoder:</code> does get called.</p>
  
  <p><strong>SimoTableViewCell.m</strong></p>
  
  <pre><code>@implementation SimoTableViewCell
  
  @synthesize mainLabel, subLabel;
  
  -(id) initWithCoder:(NSCoder *)aDecoder {
      if ( !(self = [super initWithCoder:aDecoder]) ) return nil;
  
      [self styleCellBackground];
      //style the labels
      [self.mainLabel styleMainLabel];
      [self.subLabel styleSubLabel];
  
      return self;
  }
  
  @end
  </code></pre>
  
  <p><strong>TableViewController.m</strong></p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"NearbyLandmarksCell";
      SimoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  
      //sets the text of the labels
      id&lt;SimoListItem&gt; item = (id&lt;SimoListItem&gt;) [self.places objectAtIndex:[indexPath row]];
      cell.mainLabel.text = [item mainString];
      cell.subLabel.text = [item subString];
  
      //move the labels so that they are centered horizontally
      float mainXPos = (CGRectGetWidth(cell.contentView.frame)/2 -      CGRectGetWidth(cell.mainLabel.frame)/2);
      float subXPos = (CGRectGetWidth(cell.contentView.frame)/2 - CGRectGetWidth(cell.subLabel.frame)/2);
      CGRect mainFrame = cell.mainLabel.frame;
      mainFrame.origin.x = mainXPos;
      cell.mainLabel.frame = mainFrame;
      CGRect subFrame = cell.subLabel.frame;
      subFrame.origin.x = subXPos;
      cell.subLabel.frame = subFrame;
  
      return cell;
  }
  </code></pre>
  
  <p>I have debugged the code and found that the <code>dequeue...</code> is called first, then it goes into the <code>initWithCoder:</code> and then back to the view controller code. What is strange is that the address of the cell in memory changes between <code>return self;</code> and when it goes back to the controller. And if I move the styling code back to the view controller after <code>dequeue...</code> everything works fine. It's just I don't want to do unnecessary styling when reusing cells.</p>
  
  <p>Cheers</p>