title: Table View troubles with dequeue cell
body: <p>So I am having trouble showing my data in a <code>UITableView</code>.  I do believe it has something to do with reusing the cells.  I have checked online and here at SO but have not found a solution that works for me.  Any help would be appreciated.  </p>
  
  <p>I have an Array that is populated by text and pictures.  I am then showing the information in a <code>tableView</code>.  If I were to use static sized cells everything works out fine, but the amount of text changes, so I have also implemented the <code>heightForRowAtIndexPath</code> method.  This works as well, until I scroll all the way down to the bottom.  </p>
  
  <p>After that, when I scroll back up, all the cell heights change and the display gets all jumbled.  Some text gets cut off, pictures get chopped and some of the cells only have the last portion of text.  I really think it has something to do with reusing the cells, but I don’t know how to attack this problem.  Below is my code for <code>cellForRowAtIndexPath</code> and <code>heightForRowAtIndexPath</code>.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  static NSString *CellIdentifier = @"Cell";
  
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  
  if (cell == nil)
  {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }
  
  if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[NSString class]])
  {
      NSString *label = [_theBigArray objectAtIndex:indexPath.row];
      CGSize stringSize = [label sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:NSLineBreakByWordWrapping];
  
      UITextView *textV = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 290, stringSize.height +50)];
      textV.font = [UIFont systemFontOfSize:15];
      textV.text = [_theBigArray objectAtIndex:indexPath.row];
      textV.textColor = [UIColor blackColor];
      textV.editable = NO;
      [cell.contentView addSubview:textV];
  }
  else if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[UIImage class]])
  {
      UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 290, 100)];
      imageV.contentMode = UIViewContentModeScaleAspectFit;
      imageV.image = [_theBigArray objectAtIndex:indexPath.row];
      [cell.contentView addSubview:imageV];
  }
  
  return cell;
  [tableView reloadData];
  }
  </code></pre>
  
  <p>For <code>heightForRowAtIndexPath</code></p>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  
  int rowHeight = 0.0f;
  
  if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[NSString class]])
  {    
      NSString *temp = [_theBigArray objectAtIndex:indexPath.row];
      CGSize size = [temp sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:NSLineBreakByWordWrapping];
      rowHeight = size.height+50;
  }
  else if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[UIImage class]])
  {
      rowHeight = 115.0f;
  }
  
  //NSLog(@"rowHeight is %i", rowHeight);
  
  return rowHeight;
  [tableView reloadData];
  }
  </code></pre>
  
  <p>I even tried to make two different cells and call them separately, but the same thing happens.  I did still use the same <code>heightForRowAtIndexPath</code> method.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  UITableViewCell *newCell = [[UITableViewCell alloc] init];
  
  if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[NSString class]])
  {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
  
      if (cell == nil)
      {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
      }
  
      NSString *label = [_theBigArray objectAtIndex:indexPath.row];
      CGSize stringSize = [label sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:NSLineBreakByWordWrapping];
      UITextView *textV = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 290, stringSize.height +50)];
      textV.font = [UIFont systemFontOfSize:15];
      textV.text = [_theBigArray objectAtIndex:indexPath.row];
      textV.textColor = [UIColor blackColor];
      textV.editable = NO;
      [cell.contentView addSubview:textV];
  
      newCell = cell;
  }
  else if ([[_theBigArray objectAtIndex:indexPath.row] isKindOfClass:[UIImage class]])
  {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PictureCell"];
  
      if (cell == nil)
      {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PictureCell"];
      }
  
      UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 290, 100)];
      imageV.contentMode = UIViewContentModeScaleAspectFit;
      imageV.image = [_theBigArray objectAtIndex:indexPath.row];
      [cell.contentView addSubview:imageV];
  
      newCell = cell;
  
  }
  
  return newCell;
  [tableView reloadData];
  }
  </code></pre>
  
  <p>Any ideas?</p>