Skip to content

A UIViewController subclass that implements NSFetchedResultsControllerDelegate and manages a table view binded to a custom fetch request.

Notifications You must be signed in to change notification settings

quemb/QMBFetchedResultsViewController

Repository files navigation

QMBFetchedResultsViewController

A simple UIViewController subclass that implements NSFetchedResultsControllerDelegate and manages a table view binded to a custom fetch request.

  • Simple fetch requests
  • Support of sections
  • Simple customization via overriding
  • Use Offset to manage custom sections or rows (at the top)
  • Addional Filter Controller (inspired by: lukagabric/LargeDatasetSample)

Demo

Pod

Not yet contributed but you can include it via:

pod 'QMBFetchedResultsViewController', :git => 'https://github.com/quemb/QMBFetchedResultsViewController.git'

Example

Set your managed object context via override:

- (NSManagedObjectContext *)managedObjectContext
{
    return [((QMBAppDelegate *)[[UIApplication sharedApplication] delegate]) managedObjectContext];
}

Set your fetch Request (section is optional):

- (NSFetchRequest *)getFetchRequest
{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    
    
    NSEntityDescription *entity = [NSEntityDescription
                                   entityForName:@"Sample" inManagedObjectContext:[self managedObjectContext]];
    [fetchRequest setEntity:entity];
    
    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:
                                      [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES],
                                      nil]];
    
    return fetchRequest;
}

Set your UITableViewCell - styles

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    Sample *sample = (Sample *)[self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = sample.title;
    cell.detailTextLabel.text = sample.subtitle;
}

Credits

About

A UIViewController subclass that implements NSFetchedResultsControllerDelegate and manages a table view binded to a custom fetch request.

Resources

Stars

Watchers

Forks

Packages

No packages published