title: uitableview cell delete, custom animation
body: <p>i am trying to create a custom animation for the deletion of table rows by overriding the deleteRowsAtIndexPaths method. i created the custom insert animation successfully and tried to reverse the animation for the deletion part but i get some errors: Assertion failure in -[UITableView _endCellAnimationsWithContext:] <br> 
  and <br>
  NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.(rows after update must be equal to rows before the update). <br>
  <br>
  If i don't override the deleteRows method and use tableView's default delete method, everything works fine, but not with my own method.</p>
  
  <p><br><br>
  Here is the overriden method written in my tableViewController class: <br></p>
  
  <pre><code>- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths
                withRowAnimation:(UITableViewRowAnimation)animation
  {
  
      [[super tableView] insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
      [self.tableView endUpdates]; // Populates UITableView with data
      [self.tableView beginUpdates];
      for (NSIndexPath *indexPath in indexPaths) {
          __block UITableViewCell *cell = [[super tableView] cellForRowAtIndexPath:indexPath];
          if (cell) { // If indexPath isn't visible we'll get nil here
              // Custom animation
              CGRect frame = cell.frame;
              frame.origin.x = cell.frame.size.width;
              cell.frame = frame;
              frame.origin.x = 0;
              void (^animationsBlock)() = ^{
                  cell.frame = frame;
              };
              if ([[UIView class] respondsToSelector:
                   @selector(animateWithDuration:delay:usingSpringWithDamping:
                             initialSpringVelocity:options:animations:completion:)]) {
                       [UIView animateWithDuration:0.9
                                             delay:0
                            usingSpringWithDamping:0.5
                             initialSpringVelocity:0
                                           options:0
                                        animations:animationsBlock
                                        completion:NULL];
                   } else {
                       [UIView animateWithDuration:0.3
                                             delay:0
                                           options:UIViewAnimationOptionCurveEaseIn
                                        animations:animationsBlock
                                        completion:NULL];
                   }
          }
      }
  }
  </code></pre>
  
  <p><strong>deleteRowsAtIndexPathsMethod:</strong> <br></p>
  
  <pre><code>- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths
                withRowAnimation:(UITableViewRowAnimation)animation
  {
  
      [[super tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
      [self.tableView endUpdates]; // Populates UITableView with data
      [self.tableView beginUpdates];
      for (NSIndexPath *indexPath in indexPaths) {
          __block UITableViewCell *cell = [[super tableView] cellForRowAtIndexPath:indexPath];
          if (cell) { // If indexPath isn't visible we'll get nil here
              // Custom animation
              CGRect frame = cell.frame;
              frame.origin.x = 0;
              cell.frame = frame;
              frame.origin.x = cell.frame.size.width;
              void (^animationsBlock)() = ^{
                  cell.frame = frame;
              };
              if ([[UIView class] respondsToSelector:
                   @selector(animateWithDuration:delay:options:animations:completion:)]) {
                       [UIView animateWithDuration:0.9
                                             delay:0
                                           options:UIViewAnimationOptionCurveEaseIn
                                        animations:animationsBlock
                                        completion:NULL];
                   } else {
                       [UIView animateWithDuration:0.9
                                             delay:0
                                           options:UIViewAnimationCurveLinear
                                        animations:animationsBlock
                                        completion:NULL];
                   }
          }
      }
  }
  </code></pre>
  
  <p><strong>Edit:</strong> this code is inside a method, that runs whenever i modify a cell's object. I modify an object and save it to core data, then i retrieve all the updated objects using [self populateData], then i want to run the animations: delete the old cell and insert the new updated cell somewhere at the bottom of the tableView  <br></p>
  
  <pre><code>[coreDataStack saveContext];
  [self populateData];
  
  [self.tableView beginUpdates];
  
  int oldIndex = indexPath.row;
  int newIndex = newIndexPath.row;
  if(oldIndex&lt;newIndex){
      [self deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
      [self insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationTop];
  
  } else if (oldIndex&gt;newIndex) {
      [self deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
  
      [self insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
  
  } else {
      [self.tableView reloadRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationMiddle];
  }
  
  [self.tableView endUpdates];
  </code></pre>