无效更新:iOS中第0部分中的行数无效

时间:2014-06-18 05:38:16

标签: ios uitableview

我试图隐藏并通过单击按钮显示每个部分中的表格视图单元格。我已经阅读了有关此问题的所有相关问题,但我无法找到与我的问题相关的任何答案。将它们逐个隐藏(意思不是两者)没有问题,但是当单元格中的其他部分被隐藏(删除/没有单元格)时,我单击按钮。我有这个错误:

断言失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit_Sim / UIKit-2935.137 / UITableView.m:1368 2014-06-18 13:20:26.560 Head2Head [2001:60b]无效更新:第0节中的行数无效。更新后的现有部分中包含的行数(2)必须等于行数在更新(0)之前包含在该部分中,加上或减去从该部分插入或删除的行数(0插入,0删除)和加或减移入或移出该部分的行数(0移入,0搬出去。)

这是我的代码:

-(void) commentButtonClicked:(id) sender{
UIButton *btn = (UIButton *) sender;
indexClicked = btn.tag -1;

if (!commentClicked) {
    commentClicked = YES;
}else{
    commentClicked = NO;
}

@try {
    [tableView1 beginUpdates];
    [tableView1 reloadSections:[NSIndexSet indexSetWithIndex:btn.tag-1] withRowAnimation:UITableViewRowAnimationFade];
    [tableView1 endUpdates];

}
@catch (NSException *exception) {
    NSLog(@"%@", exception);
}
@finally {

}

}

和....

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSString *numberOfRows = [commentsArray objectAtIndex:section];

if (commentClicked && indexClicked == section) {
    return 0;
}else{
    return [numberOfRows integerValue];
}

}

1 个答案:

答案 0 :(得分:0)

我认为您需要重新加载这两个部分。已隐藏的那个和你要隐藏的那个。

相关问题