0

これはさまざまな質問でカバーされていることは知っていますが、これを理解することはできません。

私の知る限り、私の設定は正しいです。私の最初のソート記述子は完全に一致しsectionNameKeyPathます。

私の顧客がこのクラッシュを起こすことはめったにありません。おそらく、通常はそれほど長く開いている画面に表示されていないためです。クラッシュはまれなので、まったく再現できませんでした。

viewWillAppear-> table reloadData->numberOfSectionsInTableView->accessorでnsfetchedresultscontrollerがフェッチを実行するとクラッシュします。

クラッシュレポーターに記録されたエラーメッセージは常に同じで、番号が異なります。 インデックス9でフェッチされたオブジェクトのセクション名は、「2」です。オブジェクトはセクション名でソートする必要があります'

statusIdフィールドを使用します。これは常に1〜5の数値です。

コード:

- (NSFetchedResultsController *)unitsFetchedResultsController
{
    if (unitsFetchedResultsController != nil) {
        return unitsFetchedResultsController;
    }

    // SELECT * from Unit
    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Unit" inManagedObjectContext:self.guestCard.managedObjectContext];
    [fetchRequest setEntity:entity];
    // make this more defensive by limiting the status ids (1-14ish are valid on the backend, we only display these) 
    NSPredicate *availablePredicate = [NSPredicate predicateWithFormat:@"available = 1"];
    [fetchRequest setPredicate:availablePredicate];
    // ORDER BY ready DESC, availableDate ASC  (ATGT - must sort by 'ready' first or else 'sectionNameKeyPath' in the NSFetchedResultsController won't work)
    NSSortDescriptor* readySortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"statusId" ascending:YES];
    NSSortDescriptor* bedroomsSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"floorplan.bedrooms" ascending:YES];
    NSSortDescriptor* bathroomsSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"floorplan.baths" ascending:YES];
    NSSortDescriptor* availableDateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"availableDate" ascending:YES];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:readySortDescriptor, bedroomsSortDescriptor, bathroomsSortDescriptor, availableDateSortDescriptor, nil]];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.guestCard.managedObjectContext sectionNameKeyPath:@"statusId" cacheName:@"unitsAvailable"];
    aFetchedResultsController.delegate = self;
    self.unitsFetchedResultsController = aFetchedResultsController;

    // Clean up
    [aFetchedResultsController release];
    [fetchRequest release];

    NSError *error = nil;
    if (![[self unitsFetchedResultsController] performFetch:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        [CoreDataErrorWriter writeCoreDataErrorToFile:error];

        perimeterAppDelegate *appDelegate = APP_DELEGATE;
        [appDelegate showCoreDataError];

        [NSException raise:@"Core Data Error" format:@"Core Data Error in %@", NSStringFromClass([self class])];
    }

    return self.unitsFetchedResultsController; // I recognize I should just return the iVar, but not the problem.
}
4

0 に答える 0