【发布时间】:2013-07-04 11:05:50
【问题描述】:
在tableview我有很多部分,在部分的第一行我有一个删除按钮,我想在点击按钮后删除部分但是它崩溃了请帮助我怎么做?这是代码...
//****** adding delete section button
CellButton *_sectionButton = (CellButton*)[cell viewWithTag:10];
_sectionButton.hidden = YES;
_sectionButton.indexPath = indexPath;
[_sectionButton addTarget:self action:@selector(sectionDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
-(void)sectionDeleteButton: (id)sender
{
CellButton *_secbtn = (CellButton*)sender;
NSInteger sectionNumber = _secbtn.indexPath.section;
[self.tableView beginUpdates];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionNumber] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
[self.tableView reloadData];
}
编辑:错误信息是:
断言失败 -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2013-07-04 04:25:15.921 估计 [9025:c07] *** 由于应用程序终止未捕获的异常“NSInternalInconsistencyException”,原因:“无效更新:无效的节数。更新后表视图中包含的节数(2)必须等于更新前表视图中包含的节数(2),加上或减去插入或删除的节数(0插入,1已删除)
【问题讨论】:
-
建议将错误信息添加到此类问题中。
-
删除行后,在 numberOfScetionsInTableview 方法中更新您的节数。
-
@allprog 这个错误...断言失败 -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2013-07-04 04:25:15.921估计 [9025:c07] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:无效的节数。更新后表视图中包含的节数(2)必须等于更新前表视图中包含的节数(2),加上或减去插入或删除的节数(0插入,1已删除)。
-
是的,这正是我在答案中描述的