Permalink
Browse files

Adding NSFetchedResultsControllerDelegate snippet

Revising UITableViewDataSource & UITableViewDelegate snippets
  • Loading branch information...
1 parent f921bef commit 5aac330f7ac889d2def933c454914516d0b619c8 @mattt mattt committed Nov 6, 2012
Showing with 60 additions and 12 deletions.
  1. +54 −0 frcd.m
  2. +1 −5 tvdel.m
  3. +5 −7 tvds.m
View
@@ -0,0 +1,54 @@
+// NSFetchedResultsControllerDelegate
+// Placeholders for the fetched results controller delegate methods
+//
+// Platform: iOS
+// Language: Objective-C
+// Completion Scope: Class Implementation
+
+#pragma mark - NSFetchedResultsControllerDelegate
+
+- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
+ [self.tableView beginUpdates];
+}
+
+- (void)controller:(NSFetchedResultsController *)controller
+ didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
+ atIndex:(NSUInteger)sectionIndex
+ forChangeType:(NSFetchedResultsChangeType)type
+{
+ switch(type) {
+ case NSFetchedResultsChangeInsert:
+ [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
+ break;
+ case NSFetchedResultsChangeDelete:
+ [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
+ break;
+ }
+}
+
+- (void)controller:(NSFetchedResultsController *)controller
+ didChangeObject:(id)object
+ atIndexPath:(NSIndexPath *)indexPath
+ forChangeType:(NSFetchedResultsChangeType)type
+ newIndexPath:(NSIndexPath *)newIndexPath
+{
+ switch(type) {
+ case NSFetchedResultsChangeInsert:
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+ break;
+ case NSFetchedResultsChangeDelete:
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+ break;
+ case NSFetchedResultsChangeUpdate:
+ [self configureCell:[self.tableView cellForRowAtIndexPath:indexPath] forRowAtIndexPath:indexPath];
+ break;
+ case NSFetchedResultsChangeMove:
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
+ break;
+ }
+}
+
+- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
+ [self.tableView endUpdates];
+}
View
@@ -8,9 +8,5 @@
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- switch (indexPath.section) {
- case <#constant#>:
- <#statements#>
- break;
- }
+ <# statements #>
}
View
@@ -12,13 +12,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- switch (section) {
- case <#constant#>:
- <#statements#>
- break;
- default:
- return 0;
- }
+ return <# number #>
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -31,3 +25,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
+
+- (void)configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
+ <# statements #>
+}

0 comments on commit 5aac330

Please sign in to comment.