あなたの問題
セクションの 1 つが前のセクションよりも長くなっています。
で 1 つ少ないセクションをレポートすることでセクション 0 を非表示にするためnumberOfSectionsInTableView:
、編集モードではすべてのデリゲート メソッドでセクション番号を調整する必要があります。それらの1つはそうしていません。
// every delegate method with a section or indexPath must adjust it when editing
- (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (tvController.editing) section++;
return [[customers objectAtIndex:section] count];
}
- (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
{
int section = indexPath.section;
if (tvController.editing) section++;
id customer = [[customers objectAtIndex:section] indexPath.row];
// etc
}
私のアプローチ
UITableView reloadSections:withRowAnimation:指定されたセクションをアニメーションでリロードします。setEding:animated:
デリゲート メソッドから呼び出します。
- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:animation];
[self.tableView reloadSectionIndexTitles];
self.navigationItem.hidesBackButton = editing;
}
デリゲートは、非表示セクションに行やタイトルがないことも示す必要があります。
- (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.editing && section == 0) {
return 0;
}
return [[customers objectAtIndex:section] count];
}
- (NSString*) tableView:(UITableView*) tableView titleForHeaderInSection:(NSInteger) section
{
if (self.editing && section == 0) {
return nil;
}
[[customers objectAtIndex:section] title];
}