commitEditingStyleを使用してUITableViewから行を削除すると、次のエラーメッセージが表示され、アプリケーションがクラッシュします。しかし、私はメッセージに従って部3から矛盾を削除していている奇妙なことは、セクション4行を削除するとクラッシュする - セクションの不一致が更新されない
からである中*アサーションの失敗 - [のUITableView _endCellAnimationsWithContext:]、/SourceCache/UIKit_Sim/UIKit-1262.60。 3/UITableView.m:920 2010-11-22 19:56:44.789 bCab [23049:207] *キャッチされていない例外 'NSInternalInconsistencyException'のためアプリを終了します。理由:無効な更新:セクション4の行数が無効です。更新(1)の後の既存のセクションに含まれる行の数は、更新前のそのセクションに含まれる行の数(0)、そのセクションに挿入または削除された行の数をプラスまたはマイナスしたもの、0削除されました)。 '
データソースでは、セクション3の行数に応じてセクション4を更新します。セクション3から行が削除されると、セクション4の行数は0から1になります。 。これを避ける方法はありませんか?
いずれのポインタも高く評価されます。おかげさまで
UPDATE:
numberOfSectionsInTableView - (NSInteger)numberOfSectionsInTableView:(のUITableView *)のtableView { リターン6。
}
numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
bCabAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (section == 0) { // First name, last name
return 2;
}
else if (section == 1) { // Password
return 2;
}
else if (section == 2) { // Mobile, DOB , Gender
return 3;
}
else if (section == 3) { // credit cards
return [creditCards count];
}
else if (section == 4) { // Add credit card
if ([creditCards count] >= 3) {
return 0;
}
else {
return 1;
}
}
else if (section == 5) {
return 0;
}
return 0;
}
commitEditingStyle
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (indexPath.section == 3) {
// Delete the row from the data source
NSLog(@"%d %d", indexPath.section, indexPath.row);
[creditCards removeObjectAtIndex:indexPath.row];
// Delete from backend
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
//[tableView reloadData];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
私は同じ結果で[tableView reloadData]を試してみました。
ありがとうございました!
は、あなたのnumberOfSectionsInTableViewとのtableViewを投稿することができますか? – MathieuF
行を削除するコードを投稿できますか? –