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
- calling
reloadData
on the search table view, or
- returning
YES
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.
- Compare
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.
- Return
NO
from shouldReloadTableForSearchString
or shouldReloadTableForSearchScope
.
As I said, this is just an idea but I think it could work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…