title: App crashes on call to 'tableView endUpdates'
body: <p>I'm currently working on an implementation of an <a href="https://stackoverflow.com/questions/18973573/ios-7-how-to-display-a-date-picker-in-place-in-a-table-view">inline UIDate picker</a> inside of a UITableViewCell. </p>
  
  <p>I'm able to show and hide this picker cell when I select the cell directly above where that cell should be inserted, which is the behavior that I expect. However, the app crashes if I select any other cells in the table view: </p>
  
  <pre><code>*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:1582
  </code></pre>
  
  <p>After looking at the <a href="https://stackoverflow.com/questions/14027118/my-app-crashes-when-i-select-a-cell-on-a-table-view-but-i-cant-find-where-in-the">accepted answer to this SO question</a>, I added an exception breakpoint, and I've found out that the app is crashing at the call to <code>[tableView endUpdates];</code> in <code>didSelectRowAtIndexPath</code>:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  
      // Check to see if the "Only Alert From" row was selected. The cell with the picker should be below this one.
      if (indexPath.section == TimeOfDaySection &amp;&amp; indexPath.row == HourTimeZoneRow  &amp;&amp; self.timePickerIsShowing == NO){
  
          [tableView beginUpdates];
          [self showTimePicker];
          [tableView endUpdates];
  
      } else{
          [tableView beginUpdates];
          [self hideTimePicker];
          [tableView endUpdates];
          [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
      }
      [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  }
  </code></pre>
  
  <p>That said, I'm not sure how to proceed. If I comment out the call to <code>[tableView endUpdates];</code>, the app won't crash when other cells are selected, BUT the cell with the picker view won't hide. Does anyone have any suggestions? Thank you!  </p>
  
  <p>EDIT: Below is my code for <code>showTimePicker</code> and <code>hideTimePicker</code>:</p>
  
  <pre><code>- (void)showTimePicker
  {
      self.timePickerIsShowing = YES;
      self.timePicker.hidden = NO;
  
      //Create the index path where we insert the cell with the picker
      NSIndexPath *indexPath = [NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection];
  
      [self.tableView beginUpdates];
      [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
      [self.tableView endUpdates];
  
      self.timePicker.alpha = 0.0f;
      [UIView animateWithDuration:0.25 animations:^{
          self.timePicker.alpha = 1.0f;
          //This is the row where the picker cell should be inserted
          [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection]] withRowAnimation:UITableViewRowAnimationFade];
          [self.tableView reloadData];
      }];
  }
  
  - (void)hideTimePicker {
      self.timePickerIsShowing = NO;
      self.timePicker.hidden = YES;
  
      //Create the index path where we delete the cell with the picker
      NSIndexPath *indexPath = [NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection];
      [self.tableView beginUpdates];
      //Delete the picker row
      [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
      [self.tableView endUpdates];
      [UIView animateWithDuration:0.25
                       animations:^{
                           self.timePicker.alpha = 0.0f;
                       }
                       completion:^(BOOL finished){
                           self.timePicker.hidden = YES;
                       }];
  }
  </code></pre>
  
  <p>EDIT 2: After reading <a href="https://stackoverflow.com/questions/6221248/iphone-app-crashes-when-a-row-of-uitableview-is-deleted?rq=1">this SO thread</a>, I believe the problem may be with my <code>numberOfRowsInSection</code> method: </p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      switch (section) {
          case NotificationsSection:
              return TotalPreferencesRows;
              break;
          case RedZoneSection:
              return TotalRedZoneRows;
              break;
          case TimeOfDaySection:
              if (self.timePickerIsShowing) {
                  return TotalTimeOfDayRows + 1;
              }
  //            else if (self.timePickerIsShowing == NO){
  //                return TotalTimeOfDayRows;
  //            }
              else{
                  return TotalTimeOfDayRows;
              }
              return TotalTimeOfDayRows;
              break;
          default:
              return 0;
              break;
      }
  }
  </code></pre>