Database Reference
In-Depth Information
The score labels update as before, but this reveals another problem. If you tap
around enough times, you might get into a state where teams within a qualifying
zone are not ranked by number of wins. For example, in the previous screenshot,
you can see Cameroon below Algeria. However, Cameroon has 16 wins and Algeria
6. Also, when the cells do move around, it's pretty jumpy, almost as if you were
completely reloading the table every time something changed. :]
Maintaining the relative order of the table view's cells would require you to write
some logic to determine when cells need to be reordered, then calling the
appropriate UITableView APIs to make it happen. Fortunately, you don't have to do
any of that—a common theme in this chapter!
The fetched results controller delegate can tell you if something needs to be moved,
inserted or deleted due to a change in the fetched results controller's result set.
Replace the implementation of controllerDidChangeContent that you just added
with the following three delegate methods to see this in action:
func controllerWillChangeContent(controller:
NSFetchedResultsController !) {
tableView . beginUpdates ()
}
func controller(controller: NSFetchedResultsController ,
didChangeObject anObject: AnyObject ,
atIndexPath indexPath: NSIndexPath !,
forChangeType type: NSFetchedResultsChangeType ,
newIndexPath: NSIndexPath !) {
switch type {
case .Insert:
tableView . insertRowsAtIndexPaths ([newIndexPath],
withRowAnimation: . Automatic )
case .Delete:
 
Search WWH ::




Custom Search