简体   繁体   English

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

[英]Invalid update: invalid number of rows in section 0 in iOS

I am trying to Hide and show the table view cells in each section by clicking a button. 我试图通过单击按钮来隐藏和显示每个部分中的表格视图单元格。 I have read all the related issue about this but i can't see any relevant answer to my problem. 我已经阅读了与此有关的所有相关问题,但看不到任何有关我的问题的答案。 There is no problem in hiding them one by one (meaning not both), but when the other section in a cell is hidden (removed/no cell), then i click the button. 将它们一个一个地隐藏(不是全部都包含)是没有问题的,但是当一个单元格中的另一部分被隐藏时(被删除/没有单元格),那么我单击按钮。 i am having this error: 我有这个错误:

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:1368 2014-06-18 13:20:26.560 Head2Head[2001:60b] Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). -[UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit_Sim / UIKit-2935.137 / UITableView.m:1368中的声明失败:无效的更新:第0节中的行数无效:无效的更新:第0节中的行数。更新(2)之后现有节中包含的行数必须等于更新(0)之前该节中包含的行数,加上或减去从该节中插入或删除的行数(0插入,删除0),再加上或减去移入或移出该部分的行数(移入0,移出0)。

And here is my code: 这是我的代码:

-(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 {

}

} }

And.... 和....

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

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

} }

I think you need to reload both sections. 我认为您需要重新加载两个部分。 The one that is already hidden and the one you are going to hide. 已经被隐藏的一个和将要隐藏的一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 5:更新无效:部分中的行数无效 - ios 5: Invalid update: invalid number of rows in section iOS:无效更新:第 0 节中的行数无效 - iOS: Invalid update: invalid number of rows in section 0 无效更新:第0部分UITableView中的行数无效 - Invalid update: invalid number of rows in section 0 UITableView NSInternalInconsistencyException(无效更新:第0部分无效的行数) - NSInternalInconsistencyException(Invalid update: invalid number of rows in section 0) 无效的更新:部分中的行数无效 - Invalid update: invalid number of rows in section '无效更新:第 0 节中的行数无效 - 'Invalid update: invalid number of rows in section 0 无效的更新:部分中的行数无效 - Invalid update: invalid number of rows in section 无效更新:使用 NSFetchedResultsController 的第 0 节中的行数无效 - Invalid update: invalid number of rows in section 0 with NSFetchedResultsController iOS 8:从NSFetchedResultsController的委托捕获了一个异常,无效的更新:第0节中的行数无效 - iOS 8: An exception was caught from the delegate of NSFetchedResultsController, Invalid update: invalid number of rows in section 0 NSInternalInconsistencyExceptionException原因:'无效的更新:部分0中的行数无效' - NSInternalInconsistencyException reason: 'Invalid update: invalid number of rows in section 0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM