UITableView
ユーザーが部門を選択できるようにする、かなり一般的なグループ化があります。行を選択すると、アクセサリ ビューを更新して新しい行にチェックマークを表示し、前の行から削除します。
テーブルビューの編集も許可します。編集モードでは、チェックマークは非表示になっていますが、これで問題ありません。しかし、ユーザーが現在選択されている (チェックされている) 部門の行を削除した場合は、プログラムでチェックマークを移動する必要があります。
新しい部門が使用されているときにチェックマークを追加および削除するために使用するのと同じアプローチを使用してみました。
- (void)deleteDepartmentAtIndex:(NSInteger)index
{
//if the current item is using the deleted department, move the checkmark
Department *dept = [self.departments objectAtIndex:index];
if (self.item.department == dept)
{
UITableViewCell *noneCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:self.departments.count inSection:0]];
noneCell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.departments.count inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
//delete the department and save
[dept.managedObjectContext deleteObject:dept];
//delete the row
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
}
ただし、テーブル ビューが編集モードの場合、行にチェック マーク アクセサリがありません。編集モードのまま行を手動でリロードしようとさえしました (上記のコードに見られるように)。
テーブル ビューが編集モードを終了したときに行のアクセサリが更新されるようにするにはどうすればよいですか?