title: Attempt to create two animations for cell
body: <p>I would like to create cell by expand and collapse. To do this i animate the cell by reloading. When i expand it works fine. But when i collapse it crashes and the reason is Attempt to create two animations for cell. I know Ive given same array paths and it wont reload two cell at the time. Is there a way to fix this.</p>
  
  <p>I am new to coding, so i would be happy to get a simple solution.</p>
  
  <p>Code:</p>
  
  <p>The reason am using lastSelIPath is when first cell is expanded and touch the second cell the first cell would collapse and the second cell would expand.</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
      NSIndexPath* lastSelIPath = [ NSIndexPath indexPathForRow:selectedIndex_ inSection:0 ];
  
      [ tableView deselectRowAtIndexPath:indexPath animated:YES ];
  
      if (selectedIndex_ == indexPath.row)
      {
          selectedIndex_ = -1;
      }
      else
      {
          selectedIndex_ = indexPath.row;
      }
  
      NSIndexPath* ipath = [ NSIndexPath indexPathForRow:indexPath.row inSection:0 ];
  
      NSArray* indexPathArr = [ NSArray arrayWithObjects:lastSelIPath, ipath, nil ];
  
  
      [ tableView beginUpdates ];
  
      [ tableView reloadRowsAtIndexPaths:indexPathArr withRowAnimation:UITableViewRowAnimationAutomatic ];
  
      [ tableView endUpdates ];
  }
  </code></pre>
  
  <p>So what i did now I set a condition and reload the one i wanted. Is it a correct method to follow please help.</p>
  
  <p>Modified code:</p>
  
  <pre><code>if ( lastSelIPath.row == ipath.row )
      {
          [tableView reloadRowsAtIndexPaths:@[ipath] withRowAnimation:UITableViewRowAnimationAutomatic];
      }
      else
      {
          [tableView reloadRowsAtIndexPaths:@[lastSelIPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  
          [tableView reloadRowsAtIndexPaths:@[ipath] withRowAnimation:UITableViewRowAnimationAutomatic];
      }
  </code></pre>