Amm*_*mad 2 objective-c uitableview
在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];
}
Run Code Online (Sandbox Code Playgroud)
编辑:错误消息是:
-[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已删除)
我猜会numberOfSectionsInTableView:返回之前的部分数量。您必须确保您告诉表视图执行的操作也发生在数据源中。也就是说,如果您删除了一个部分,则该部分numberOfSectionsInTableView还必须返回一个比以前少 1 的数字。这同样适用于细胞和其他一切。这可能在您收到的错误中有所描述。
| 归档时间: |
|
| 查看次数: |
7901 次 |
| 最近记录: |