0
votes

I have a head view (View A) with a segmented control. Segment 0 loads a FRC, and sets the sectionnamekeypath from a non-transient property and sorts on it.

Segment 1 loads a FRC, sets the sectionNameKeyPath from a transient property (month and year as in Apple's example pretty much) and sorts on the same non-transient property segment 0 does.

When a cell of Segment 0's FRC is clicked, it pushes to View B, here a new FRC loads selection-specific objects using a predicate. It sets its sectionNameKeyPath from a second transient property and sorts on the same non-transient property the other 2 do.

The following is what happens:

  1. View A:

    Switch between Segment 0 and 1 multiple times. The FRCs load what they're supposed to.

    Select a cell in segment 0 --> this correctly pushes View B

  2. View B:

    The FRC loads as intended.

    Press the back button --> the view correctly dismissed back to view A.

  3. View A:

    Segment 0 and its FRC are correctly loaded and shown

    Select segment 1: Error:
    
    "has an out of order section name **segment name from View B's section**"
    

I find it very weird that the error it gives, contains the sectionname from the FRC on the previous view. I set the FRC and its delegate to nil when the view WillDisAppear.

When I Breakpoint the transient properties, I can see that it only requests segment 1's FRC so it doesn't seem to make sense that it can still see View B's sections?

2

2 Answers

0
votes

Issue can be because you are using same cache for both the NSFetchedResultsController instances. Pass different cache names when creating instance,

_fetchController = [[KREFetchedResultController alloc] initWithFetchRequest:request
                                                       managedObjectContext:context
                                                         sectionNameKeyPath:@"sectionKey"
                                                                  cacheName:@"mycache"];

You can also delete the cache when not required by calling NSFetchedResultsController's class method deleteCacheWithName: to delete particular cache containing cached section information,

/* Deletes the cached section information with the given name.
    If name is nil, then all caches are deleted.
*/
+ (void)deleteCacheWithName:(NSString *)name;

Or pass nil to delete all caches.

If you do not wish to cache then pass cache name as nil when creating fetched results controller.

Hope that helps!

0
votes
  • List item

I think I solved it.. Breakpointed nearly every line of code but that got me nowhere. The caching seperately did not solve it.

I set my controllers and their delegates to nil in the last lines of the prepareforsegue method. I moved that code to reside within the specific segue's if method

if ([[segue identifier] isEqualToString:@"segueID"]) {

//set destination VC's properties first since they might come from the FRC.

 _fetchedResultsController.delegate = nil;
 _fetchedResultsController = nil;
}

and it suddenly works.. Very strange, I thought it would get executed either way, either in the viewDidUnload, or at the end of the prepareForSegue. For some reason these FRC delegates are very persistent across viewcontrollers.

Update:

I made a typo in my transientproperty as well. Pretty sure that was it. The PrimitiveProperty1 was being set with Transient property 1 and 2 ... Auto-complete filled it in I guess :)