【发布时间】:2013-07-28 16:03:42
【问题描述】:
我有一个静态的 UITableView,它是通过故事板配置的。我正在尝试使用 insertRowsAtIndexPaths:withRowAnimation: 在 didSelectRowAtIndexPath 期间插入一些行,但出现错误:
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayI objectAtIndex:]:索引 2 超出范围 [0 .. 1]'。
我已经实现了 numberOfRowsInSection,但每次仍然出现此错误。它是否与表是静态的而不是动态的有关?谢谢。
if (indexPath.section == 1) {
if (indexPath.row == 1) { // Map Type Cell
self.isSelectingMapType = YES;
NSArray *indexPaths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:2 inSection:1], [NSIndexPath indexPathForRow:3 inSection:1], [NSIndexPath indexPathForRow:4 inSection:1], [NSIndexPath indexPathForRow:5 inSection:1], nil];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
//[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1) {
if (self.isSelectingMapType == YES) {
return 6;
}
return 2;
}
return 0;
}
【问题讨论】:
标签: ios uitableview insert tableview