Database Reference
In-Depth Information
[[self tableView] deleteRowsAtIndexPaths:oldArray
withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] insertRowsAtIndexPaths:newArray
withRowAnimation:UITableViewRowAnimationFade];
break
;
}
}
An
NSFetchedResultsChangeInsert
is fired when a new object is inserted that we
need to display in our
UITableView
. When we receive this call, we pass it along
to the
UITableView
and tell the table view what type of animation to use.
An
NSFetchedResultsChangeDelete
is fired when an existing object is removed. Just
as we do with an insert, we pass this information along to the
UITableView
and
tell it what type of animation to use when removing the row.
An
NSFetchedResultsChangeUpdate
is fired when an existing object has changed
internally, in other words, when one of its attributes has been updated. We
do not know from this call if it is an attribute that we care about. Instead of
spending time determining whether we
should
update the row, it is generally
cheaper to just update the row.
An
NSFetchedResultsChangeMove
is fired when a row is moved. The move could be
as a result of a number of factors but is generally caused by a data change
resulting in the row being displayed in a different location. In our example,
if the name or type of a recipe were altered, it would most likely cause this
change type. It is quite possible—and common—to receive an
NSFetchedResults
-
ChangeMove
and an
NSFetchedResultsChangeUpdate
in the same batch of changes.
When this change type is received, we make two calls to the
UITableView
: one
to remove the row from its previous location and another to insert it into its
new location.
-controller: sectionIndexTitleForSectionName:
We use this method when we want to massage the data coming back from
our
NSFetchedResultsController
before it is passed to the
UITableView
for display. One
situation where this might be necessary is if we want to remove any extended
characters from the title before it is displayed; another example is if we want
to add something to the displayed title that is not in the data.
- (NSString*)controller:(NSFetchedResultsController*)controller
sectionIndexTitleForSectionName:(NSString*)sectionName
{
return
[NSString stringWithFormat:@
"[%@]"
, sectionName];
}