title: IPhone reloadRowsAtIndexPaths weird animation
body: <p>Hi I'm new to this iPhone dev and I have a question about reloadRowsAtIndexPaths. When the user taps one cell, it will expand showing buttons underneath it and tapping it again closes the cell. This works fine when opening and closing cell one at a time, but I have this weird animation when tapping cells in sequence like cell one is tapped, cell 2 is tapped the animation gets weird. Please see the video to fully understand the situation and sorry for the low quality.</p>
  
  <p><a href="http://www.youtube.com/watch?v=R28Rmti9wPQ" rel="nofollow">http://www.youtube.com/watch?v=R28Rmti9wPQ</a></p>
  
  <p>and here's the code for reloading the cells</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
      (NSIndexPath *)indexPath {
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
  
  selectedIndexPath = indexPath; 
  
  //close the selected cell if it's open
  if(selectedIndex == indexPath.row)
  {
      selectedIndexPath = nil;
  
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
      selectedIndex = -1;
      selectedIndexPath = indexPath;
      return;
  }
  
  //this will reload the previously open cell to avoid it from being recycled
  if(selectedIndex &gt;= 0)
  {
      NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
      selectedIndex = indexPath.row;
  
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];  
  }
  
  //now reload the selected cell
  if(selectedIndexPath != nil &amp;&amp; [selectedIndexPath isEqual:indexPath]) {
  
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }
  
  }
  </code></pre>
  
  <p>and here's the code for creating the cellForRowAtIndexPath.</p>
  
  <pre><code>if(selectedIndexPath != nil &amp;&amp; [selectedIndexPath isEqual:indexPath]) {
      selectedIndex = indexPath.row;
      static NSString *CustomCellIdentifier = @"CustomCell";
      CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
      if (customCell == nil) { 
          customCell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease];
      }
      customCell.locationLabelOutlet.text = [usgsFeeds objectAtIndex:[indexPath row]];
      customCell.dateLabelOutlet.text = [pubDateArr objectAtIndex:[indexPath row]];
  
      float thisMag;
      thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue];
      customCell.magnitudeImageOutlet.image = [self imageForMagnitude:thisMag];
      [customCell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
      return customCell;
  }
  
  else{
  
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
      if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
          locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 225, 20)] autorelease];
          locationLabel.tag = kLocationLabelTag;
          locationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
          locationLabel.backgroundColor = [UIColor clearColor];
          [cell.contentView addSubview:locationLabel];
  //and all other views for the cell....
  </code></pre>