1

我有一个包含不同部分和单元格样式的表格视图,即 iOS 设置应用程序。

我在使用 heightForRowAtIndexPath 时遇到问题。如果我包含它,每当我尝试插入一个单元格时,应用程序就会崩溃:

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'

但是,由于表格视图有这么多种单元格,我需要实现该方法。例如,大多数单元格的高度为 44 像素,但我的日期选择器单元格并不总是可见且高度为 216 像素。如果我使用自动布局,单元格的高度很好,但插入单元格的动画很跳跃。

我以前没有遇到过这个问题,但决定将表格视图中的一个部分分成两个不同的部分。现在,每当我尝试插入一个单元格时,应用程序就会崩溃。这在以前没有发生,只有在实施 heightForRowAtIndexPath 或estimatedHeightForRowAtIndexPath 时才会发生。

我发现这个 UITableView insertRowsAtIndexPaths 抛出 __NSArrayM insertObject:atIndex:'object cannot be nil' 错误 ,但它没有提供其他选择 - 它只是说不要实现 heightForRowAtIndexPath,我需要这样做。有没有办法解决这个问题?

编辑 添加了 heightForRowAtIndexPath 的实现 - 这并不复杂(我有一些用于部分和行的枚举,datePickerIndex 是日期选择器的行,如果不存在则为零)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == ScheduleEditorSectionDates && self.datePickerIndex && indexPath.row == self.datePickerIndex) return 216.0f;
    return 44.0f;
}
4

0 回答 0