Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

radianttap/UITableView-NSFetchedResultsController

Repository files navigation

Error in user YAML: (<unknown>): did not find expected comment or line break while scanning a block scalar at line 1 column 1
---
> Note: this is abandoned. 
> I don‘t recommend to use it in any new projects.
---

UITableView+NSFetchedResultsController

This is an example of how to use the UITableView with NSFetchedResultsController with the least hassle. The code is based on the investigation and hard work of Michael Fey; you can also see this gist.

His code greatly improves the usual sample code you can find around, including in Apple's sample code. Since I much prefer to extract these away and no repeat them in each UITableViewController I do, I have created this category. Simply include it and write your UITableView delegate methods in the same way.

Setup

  • [CocoaPods]
    Add pod 'UITableView+NSFetchedResultsController' to your podfile.
  • Manual
    Copy UITableView+NSFetchedResultsController.h/m to your project.

Usage

Just include the header and write your NSFetchedResultsControllerDelegate methods like this:

- (void)controller:(NSFetchedResultsController *)controller
   didChangeObject:(id)anObject
	   atIndexPath:(NSIndexPath *)indexPath
	 forChangeType:(NSFetchedResultsChangeType)type
	  newIndexPath:(NSIndexPath *)newIndexPath {

	[self.tableView addChangeForObjectAtIndexPath:indexPath
									forChangeType:type
									 newIndexPath:newIndexPath];
}

- (void)controller:(NSFetchedResultsController *)controller
  didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
		   atIndex:(NSUInteger)sectionIndex
	 forChangeType:(NSFetchedResultsChangeType)type {

	[self.tableView addChangeForSection:sectionInfo
								atIndex:sectionIndex
						  forChangeType:type];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
	
	[self.tableView commitChanges];
}

Credit

Michael Fey

About

UITV and NSFRC, sitting in a tree, forever happy

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors