ここに私の問題があります:
私はNSMutableArray *notes
と 私の のソースを持っていUITableView* _gradesTV
ます。
ここにメソッドを追加しました- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"%ld", (long)indexPath.section);
NSLog(@"%@", notes);
[_gradesTV beginUpdates];
[notes removeObjectAtIndex:indexPath.section];
[_gradesTV deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
[_gradesTV endUpdates];
NSLog(@"%@", notes);
}
[_gradesTV reloadData];
}
しかし、要素を削除すると、このエラーが発生します:
*** Terminating app due to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
しかし、MutableArray で作成した NSLog には 3 つの要素が表示されます...
removeObjectAtIndex
ノート (MutableArray)の行により、アプリが 2 回実行されたようにクラッシュします ...
ご協力ありがとうございました ...
プロジェクトをプルして試してみたい場合は...
+ボタンで成績を作成する必要があります。その後、テーブルビューでアイテムを削除してみてください。
成績を追加する場合、最初の TextField はstring
、2 番目はdouble
値、3 番目もdouble
値です。