1

G'day すべて

StackMobアプリケーションから入力した空の CoreData ストアから始まる CoreData 駆動型アプリに取り組んでいます。

必要に応じてデータをフェッチして表示する UITableView のサブクラスがありますが、StackMob から初期データを取得するのに最適な時期について少し戸惑っています。ApplicationDidFinishLaunching で (小さな plist ファイルから & ビューをテストするためだけに) 私の CoreData ストアへの入力をトリガーしたとき、私のアプリは既定の画面を表示するのに長い時間を費やしました。UITableView サブクラスでこのメソッドを変更することを検討しています...

- (NSFetchedResultsController *)frc
{
    if (_frc) return _frc;

    ...

    return _frc;
}

に...

- (NSFetchedResultsController *)frc
{
    if (_frc) return _frc;

    ...

    if ([[_frc fetchedObjects] count] == 0) {
        // Spawn NSOperation to get initial data from StackMob.
        // & use it to populate my CoreData store.
    }

    return _frc;
}

その場合、NSOperation をサブクラスにして、その後のデータ更新に再利用できるようにします。[[_frc fetchedObjects] count] == 0エンティティからすべてのデータをフェッチしているため、チェックしています。

取るべき良いアプローチはありますか?そうでない場合、より良いアプローチは何でしょうか?

私が使用している一部のアプリで見たようなユーザー エクスペリエンスを提供したいと考えています。アイテムがダウンロードされて CoreData ストアに追加されると、「ホーム」画面にアイテムが表示されます。

乾杯 & TIA、ペドロ :)

4

1 に答える 1

1

まず、NSPredicateを作成して、Core Dataから情報をフェッチします(この場合はNSSetを想定しています)。

NSMutableSet yourMutableDataSetYouGotFromCoreData = [self.yourCoreDataObject mutableSetValueForKey:@"yourCoreDataSetData"];

NSPredicate *yourDataFilter = [NSPredicate predicateWithFormat:@"SELF IN %@",yourMutableDataSetYouGotFromCoreData];

次に、述語を使用してフェッチ結果コントローラーを作成します

// Fetched results controller
NSFetchedResultsController *yourFetchedResults = [YOURCOREDATAOBJECT fetchRequestAllGroupedBy:nil 
                                                                                                withPredicate:supplyRegisterFilter];

次に、この情報をテーブルにフィードします

[self.yourTable updateTableData:yourFetchedResults];

次に、セルデータコンテンツを作成するテーブルで、次のようなものを使用して、フェッチされた結果コントローラーからデータを取得します

-(void) updateTableData:(NSFetchedResultsController*)fetched
{
       self.fetchedResultsController = fetched;

       if(self.fetchedResultsController)
          [self.tableView reloadData];

 }


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.fetchedResultsController.fetchedObjects count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YourCustomCellType *cell = (YourCustomCellType *)    [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell)
    {
        NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
        cell = [topLevelItems objectAtIndex:0];
    }

    [self configureCellData atIndexPath:indexPath];

    return cell;
}

- (void) configureCellData:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    YourCustomCellType *customCell = (YourCustomCellType *)cell;
    id obj = [[fetchedResultsController fetchedObjects] objectAtIndex:indexPath.row];
    [customCell setCellDataFromId:obj];
}
于 2011-08-30T19:29:26.630 に答える