1

私はセクションにグループ化されたデータNSFetchedResultsControllerで自分の の 1 つを埋めるために取り組んでいます。UITableViewここで、フェッチされないデータによって作成されたすべてのフェッチ済みセクションの上に新しいセクションを追加したいと思います (そのための追加の配列を作成しています)。NSFetchedResultsControllerすべての素晴らしい動作を壊すことなく、その配列を挿入する良い方法はありますか?

アップデート

私がこれまでに試したことは、 のすべての使用を手動で調整することですindexPath。メソッド (つまり-tableView:numbersOfRowsInSection) get が呼び出されるたびに、それが最初のセクションであるかどうかを確認し、そうであれば、. の代わりに配列からデータを取得しますNSFetchedResultsControllerNSIndexPathそうでない場合は、元indexPathの行とセクション 1 を使用して新しいを作成し、にアクセスしfetchedResultsます。これはかなり素朴なアプローチのようです。少なくとも、これは(まだ)私にはうまくいきません。

ありがとう!
–f

4

1 に答える 1

3

UITableViewDataSource静的セクションと動的セクションが混在する を作成しました。私はNSIndexPathあなたが計画したように修正してそれを行います。NSIndexPathのデリゲート メソッドのも変更することが重要ですNSFetchedResultsControllerDelegate

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    indexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:kSectionWithAdditionalRowIndex];
    if (newIndexPath) {
        newIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row + 1 inSection:kSectionWithAdditionalRowIndex];
    }

    [super controller:controller didChangeObject:anObject atIndexPath:indexPath forChangeType:type newIndexPath:newIndexPath];
}

サンプルは、クラスCBUIFetchResultsDataSource.mのサブクラスから取得されます。これはUITableViewDataSourceNSFetchedResultsController. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section-(id)objectAtIndexPath:(NSIndexPath*)indexPathおよびも上書きする必要があり-(NSIndexPath*)indexPathForObject:(id)objectました。

于 2012-09-26T20:25:08.187 に答える