I\'ve been reading all the documentation about UISearchDisplayController
and its delegate
but I can\'t find any way to animate the table view when
When the search string or scope has changed, you assign a new fetch request for the fetched results controller and therefore have to call performFetch
to get a new result set. performFetch
resets the state of the controller, and it does not trigger any of the FRC delegate methods.
So the table view has to be updated "manually" after changing the fetch request. In most sample programs, this is done by
reloadData
on the search table view, orYES
from shouldReloadTableForSearchString
or shouldReloadTableForSearchScope
.The effect is the same: The search table view is reloaded without animation.
I don't think there is any built-in/easy method to animate the table view update when the search predicate changes. However, you could try the following (this is just an idea, I did not actually try this myself):
Before changing the fetch request, make a copy of the old result set:
NSArray *oldList = [[fetchedResultsController fetchedObjects] copy];
Assign the new fetch request to the FRC and call performFetch
.
Get the new result set:
NSArray *newList = [fetchedResultsController fetchedObjects];
Do not call reloadData
on the search table view.
oldList
and newList
to detect new and removed objects. Call insertRowsAtIndexPaths
for the new objects and deleteRowsAtIndexPaths
for the removed objects. This can be done by traversing both lists in parallel.NO
from shouldReloadTableForSearchString
or shouldReloadTableForSearchScope
.As I said, this is just an idea but I think it could work.