I have a table view with various sections and cell styles, i.e. the iOS settings app.
I'm having a problem with heightForRowAtIndexPath. If I include it, the app crashed whenever I try to insert a cell:
2014-07-27 17:24:48.660 Schoodle[413:31582] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
However, because the table view has such a variety of cells, I need to implement the method. For example, most cells are 44px tall, but I have date picker cells that are not always visible and are 216px tall. If I use auto layout, the heights of the cells are fine, but the animation for inserting the cells is jumpy.
I wasn't having this problem before, but decided to split up one of the sections in the table view into two different sections. Now, whenever I try to insert a cell, the app crashes. This wasn't happening before and only happens if heightForRowAtIndexPath or estimatedHeightForRowAtIndexPath are implemented.
I found this UITableView insertRowsAtIndexPaths throwing __NSArrayM insertObject:atIndex:'object cannot be nil' error but it offers no alternative - it simply says don't implement heightForRowAtIndexPath, which I need to do. Is there any way to solve this?
Edit Added implementation of heightForRowAtIndexPath - It's nothing complicated (I have some enums for sections and rows, datePickerIndex is the row of the date picker or zero if it doesn't exist)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == ScheduleEditorSectionDates && self.datePickerIndex && indexPath.row == self.datePickerIndex) return 216.0f;
return 44.0f;
}