0

いくつかのアドバイスが必要です:NSFetchedResultControllerはこれを行うことができますか?

UITableView:
  [section name] <= {entity: Section, value: title}
    [cell title] <= {entity: Cell, value: title}

Model:
  [entity: Section, properties: title] <->> [entity: Cell, properties: title, imgPath]

トラブル: セクションの数とそのタイトルが機能しているため、セルとの関係からオブジェクトをフェッチできません

手伝ってくれてありがとう...

4

1 に答える 1

1

それは可能であるべきです。sectionNameKeyPath実際、「section.title」に設定して FRC を作成すると、「標準」のテーブル ビュー データ ソース メソッドとフェッチされた結果コントローラーのデリゲート メソッドを使用できると思います。

// Fetch "Cell" entities:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Cell"];

// First sort descriptor for grouping the cells into sections, sorted by section title:
NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"section.title" ascending:YES];
// Second sort descriptor for sorting the cells within each section:
NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObjects:sort1, sort2, nil];

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc]
                                        initWithFetchRequest:request
                                        managedObjectContext:context
                                          sectionNameKeyPath:@"section.title"
                                                   cacheName:nil];

( Cellエンティティから Section エンティティへのsection関係があると想定しています。)

于 2012-10-15T17:37:30.073 に答える