title: Deleting a cell in a tableview while searchbar is active - CoreData Error
body: <p>I am pretty new to IOS Programming and this will be my first app. I have a TableViewController to show the Data History (CoreData) and I am trying to implement a SearchBar (iOS8). Besides a minor issure with the layout it works fine (see Screenshot, the tableView does not have full width and there is this lupe...?, does anyone know why this is?) 
   <img src="https://i.stack.imgur.com/nGco1.png" alt="enter image description here"></p>
  
  <p>My bigger problem is that when I delete a row without using the searchbar it works, but when I am searching for an entry and try to delete, it deleted it but I get an exception and the view gets stuck with the red "Deletion"-Button. If I go back to the main view and back to the tableview the view is updated..</p>
  
  <blockquote>
    <p>*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.93/UITableView.m:1582
    2015-06-24 10:55:25.635 Pedal[9203:284856] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)</p>
  </blockquote>
  
  <p>Here's my code for the two methods I think are relevant (correct me if I am wrong)</p>
  
  <pre><code>- (void)tableView:(UITableView *)inTableView commitEditingStyle:(UITableViewCellEditingStyle)inStyle forRowAtIndexPath:(NSIndexPath *)inIndexPath {
  if(inStyle == UITableViewCellEditingStyleDelete) {
      //[inTableView beginUpdates];
  
      RecordingInfo *theItem = [self entryAtIndexPath:inIndexPath]; 
      NSError *theError = nil;
  
      [self.managedObjectContext deleteObject:theItem];
      if([self.managedObjectContext save:&amp;theError]) {
  
          if(self.searchController.active) {
              NSMutableArray *theResult = [self.searchResult mutableCopy];
  
              [theResult removeObjectAtIndex:inIndexPath.row];
              self.searchResult = theResult;
              [inTableView deleteRowsAtIndexPaths:@[inIndexPath]
                                 withRowAnimation:UITableViewRowAnimationFade];
              NSLog(@"deletion successful");
          }
      }
      else {
          NSLog(@"Unresolved error while deleting %@", theError);
      }
      //[self.tableView endUpdates];
  }   
  }
  </code></pre>
  
  <p>is it possible I need to add a similar if-question in controller:didChangeObject:?</p>
  
  <pre><code>- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
  
  UITableView *tableView = self.tableView;
  
  switch(type) {
  
      case NSFetchedResultsChangeInsert:
          [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight];
          break;
  
      case NSFetchedResultsChangeDelete:
          [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
          break;
  
      case NSFetchedResultsChangeUpdate:
          [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
          break;
  
      case NSFetchedResultsChangeMove:
          [tableView deleteRowsAtIndexPaths:[NSArray
                                             arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
          [tableView insertRowsAtIndexPaths:[NSArray
                                             arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
          break;
  }
  }
  </code></pre>
  
  <p>If anyone can help I'd be very glad, I am trying to solve this forever now!
  Thanks!</p>