多くのセクションがあり、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削除)