Created
November 11, 2013 16:31
-
-
Save Pretz/7416060 to your computer and use it in GitHub Desktop.
NSFetchedResultsController backed UITableViewController with State Restoration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - State Restoration | |
- (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)idx inView:(UIView *)view { | |
if (idx && self.fetchedResultsController) { | |
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:idx]; | |
return object.objectID.URIRepresentation.absoluteString; | |
} | |
return nil; | |
} | |
- (NSIndexPath *)indexPathForElementWithModelIdentifier:(NSString *)identifier inView:(UIView *)view { | |
if (self.fetchedResultsController) { | |
NSURL *objectURL = [NSURL URLWithString:identifier]; | |
NSPersistentStoreCoordinator *coordinator = self.fetchedResultsController.managedObjectContext.persistentStoreCoordinator; | |
NSManagedObjectID *objectID = [coordinator managedObjectIDForURIRepresentation:objectURL]; | |
NSManagedObject *object = [self.fetchedResultsController.managedObjectContext existingObjectWithID:objectID error:NULL]; | |
if (object) { | |
return [self.fetchedResultsController indexPathForObject:object]; | |
} | |
} | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment