title: UITableView with dynamic cell heights -- what do I need to do to fix scrolling down?
body: <p>I am building a teensy tiny little Twitter client on the iPhone.  Naturally, I'm displaying the tweets in a UITableView, and they are of course of varying lengths.  I'm dynamically changing the height of the cell based on the text quite fine:</p>
  
  <pre><code>- (CGFloat)heightForTweetCellWithString:(NSString *)text {
    CGFloat height = Buffer + [text sizeWithFont:Font constrainedToSize:Size lineBreakMode:LineBreakMode].height;
    return MAX(height, MinHeight);
  }
  
  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *text = // get tweet text for this indexpath
      return [self heightForTweetCellWithString:text];
    }
  }
  </code></pre>
  
  <p>I'm displaying the actual tweet cell using the algorithm in the PragProg book:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"TweetCell";
    TweetCell *cell = (TweetCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [self createNewTweetCellFromNib];
    }
    cell.tweet.text = // tweet text
    // set other labels, etc
    return cell;
  }
  </code></pre>
  
  <p>When I boot up, all the tweets visible display just fine.  However, when I scroll down, the tweets below are quite mussed up -- it appears that once a cell has scrolled off the screen, the cell height for the one above it gets resized to be larger than it should be, and obscures part of the cell below it.  When the cell reaches the top of the view, it resets itself and renders properly.  Scrolling up presents no difficulties.</p>
  
  <p>Here is a video that shows this in action:  <a href="http://screencast.com/t/rqwD9tpdltd" rel="noreferrer">http://screencast.com/t/rqwD9tpdltd</a></p>
  
  <p>I've tried quite a bit already:  resizing the cell's frame on creation, using different identifiers for cells with different heights (i.e. <code>[NSString stringWithFormat:@"Identifier%d", rowHeight]</code>), changing properties in Interface Builder...</p>
  
  <p>If there are additional code snippets I can post, please let me know.  Thanks in advance for your help!</p>