title: Misaligned tableview cells in a rotated UITableView
body: <p>As a little background, im building a rotated UITableView as a sort of sideways "picker" view. To do this, im taking a UITableView, appling a rotation transform to it, and then rotating again the UITableViewCells inside the tableview. </p>
  
  <p>The problem im having is that some of the table cells become "misaligned" - their frame gets drawn at a certain distant offset (in both the x and y dimension) from the other table cells.</p>
  
  <p>I've narrowed down that this bug occurs on the first table cell completely out of the visible tableview rect after a <code>[tableView reloadData]</code> call is made. (i.e. if I have 4 table cells, A which is completely visible and drawn, B which is half on/half off the view, and C and D which are completely off the screen and not yet rendered, when i scroll to C it is bugged, but when i scroll to D, it is not). </p>
  
  <p>Now for some code - </p>
  
  <p><strong>the containing view's init</strong> </p>
  
  <pre><code>- (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          ...
          self.tableView = [[UITableView alloc] init];
          [self addSubview:_tableView];
          [_tableView setDelegate:self];
          [_tableView setShowsVerticalScrollIndicator:NO];
          [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
          CGAffineTransform transform = CGAffineTransformMakeRotation(-1.5707963);    
          _tableView.transform = transform;
          _tableView.frame = self.bounds;
          ...
      }
      return self;
  }
  </code></pre>
  
  <p><strong>the relevant delegate methods</strong></p>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
  {
      return [tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height;
  }
  
  - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  { 
      CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
      cell.transform = transform;
  }
  </code></pre>
  
  <p><strong>the table cell's layoutSubviews</strong><br>
  <strong>edit:</strong> I manually set the size of the cell (mainly the width) based on the length on the content of the cell</p>
  
  <pre><code>- (void)layoutSubviews {
      [super layoutSubviews];
  
      // some calculations and sizing of subviews
  
      // height and width are swapped here, because the table cell will be rotated.
      self.frame = (CGRect){self.frame.origin.x,self.frame.origin.y,calculatedHeight,calculatedWidth};
  }
  </code></pre>
  
  <p>It would seem that the bugged tablecell's <code>frame.origin</code> is set incorrectly when it reaches layout subviews. Setting the frame's <code>origin.x</code> value to 0 fixes the x dimension offset problem, but obviously I can't do the same for the y dimension because this value determines the cell's position in the tableview. </p>
  
  <p>Please let me know if there's some crucial info I might be leaving out. Thanks!</p>