我正在删除UITableView
中的所有项目。因此,我加载UITableView
的数组的count = 0。删除数组中的最后一项后,重新加载表时,出现错误numberofRowInSection
。UITableView reloadData与空数组
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrProjects count];
}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"");
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[tableProject beginUpdates];
Project *project = [arrProjects objectAtIndex:indexPath.row];
[[CommonModel shared]DeleteProjectDetails:project.ProjectId];
[arrProjects removeObject:project];
[self reloadTableProject:YES];
[tableProject endUpdates];
}
}
-(void) reloadTableProject:(BOOL)isReloadRequired
{
//[arrProjects removeAllObjects];
arrProjects = [[CommonModel shared]GetAllProjects];
if(isReloadRequired)
[tableProject reloadData];
}
这是错误:
“无效更新:在部分0的行的无效数更新后的包含在现有部分 行数(1)必须是 等于到 update(2)之前包含在该段中的行数,加上或减去从 插入或删除的行数(0插入的,0删除的)和正数或负数的 行移入或在该部分中(0个移入,0个移出)。'
我每次都得到这个错误,不仅是当数组是空的。
有你设置的numberofRowInSection为您的数据源阵列的数量? –
你可以发布你删除该数组中所有对象的代码 – EmilDo
@LeeJPollard:是的,我有。 – Nitish