2012-09-27 46 views
0

我在我的應用程序中遇到了一個奇怪的問題。我想要填充我的數組。NSFetchedResultsController在進入後臺後丟失了他的行

它宣稱這種方式(作爲@propoerty (nonatomic, retain)

- (NSFetchedResultsController *)fetchedContactsController { 
    if (self->fetchedContactsController != nil) return self->fetchedContactsController; 

    // Create the fetch request 
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 

    // I want every contact... 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:self->managedObjectContext]; 
    [fetchRequest setEntity:entity]; 

    // ... whose are not associated with my order item 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (%@ IN items)", self.orderItem]; 
    [fetchRequest setPredicate:predicate]; 

    // Edit the section name key path and cache name if appropriate 
    self.fetchedContactsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self->managedObjectContext sectionNameKeyPath:nil cacheName:nil]; 

    [aFetchedResultsController release]; 
    [firstnameSortDescriptor release]; 
    [lastnameSortDescriptor release]; 
    [sortDescriptors release]; 
    [fetchRequest release]; 

    // Execute the fetch request 
    [self->fetchedContactsController performFetch:nil]; 
    return self->fetchedContactsController; 
} 
當然

,contacts.items存在。

當我的應用程序轉到後臺然後再前景,如果我做的是另

​​

每一行中我的陣列消失!

編輯:

如果我評論這些行:

// ... whose are not associated with my order item 
    //NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (%@ IN items)", self.orderItem]; 
    //[fetchRequest setPredicate:predicate]; 

的問題不要再發生!但這不是我想要的...

回答

0

好的,我發現它。 Thanks to this question,我換成這一行:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (%@ IN items)", self.orderItem]; 

通過

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", self.orderItem.recipients]; 

事實上,你如何問一個問題可以讓你解決的道路上這很有趣。