How to use NSFetchedResultsController and UISearchDisplayController?

Glancing at your code, its right there. I ran into issues using this method for changing the search. The fix: Clear your cache!

Say you initiated your fetched result controller as follows. Note the cacheName property NSFetchedResultsController *aFetchedResultsController = NSFetchedResultsController alloc initWithFetchRequest:self fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"UserSearch" As you change your predicate, simply add: NSFetchedResultsController deleteCacheWithName:@"UserSearch" Like magic, it will work nicely You will also want to monitor when the search display controller will end its search, and wipe your predicate Although this thread looks dead, I found it on google, so perhaps someone out there will get use of this. :).

Glancing at your code, its right there. I ran into issues using this method for changing the search. The fix: Clear your cache!

Say you initiated your fetched result controller as follows. Note the cacheName property. NSFetchedResultsController *aFetchedResultsController = NSFetchedResultsController alloc initWithFetchRequest:self fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"UserSearch"; As you change your predicate, simply add: NSFetchedResultsController deleteCacheWithName:@"UserSearch"; Like magic, it will work nicely.

You will also want to monitor when the search display controller will end its search, and wipe your predicate. Although this thread looks dead, I found it on google, so perhaps someone out there will get use of this. :).

This solution works, but is rather expensive, forcing the fetched results controller into numerous trips to the persistent store. Also, if you're not going to use the cache, why specify one? Just pass nil.

A much better solution, however, is what @psuedonick hints at: Leave the fetchedResultsController to do what it does best, namely managed the fetched results, and use filteredArrayUsingPredicate: on fetchedObjects to populate the filteredListContent. – Elise van Looij Dec 21 '10 at 10:03 1 To clarify, if you use the solution I describe, you should specify a cache: the fetched results controller will need it to store the fetchedObjects so that they can be effectively searched by filteredArrayUsingPredicate: – Elise van Looij Dec 21 '10 at 10:06.

According to the docs, you'll either want to filter the results into an array using a predicate or reinitialize the fetchedResultsController. Important: You must not modify the fetch request after you have initialized the controller. For example, you must not change the predicate or the sort orderings.

-- NSFetchedResultsController (I'd comment on idle's answer, but I'm karma-less. ).

It sounds like you are just interested in fetching and displaying objects. In this case, you do NOT use a search display controller. The search display controller is used with a search bar to help with allowing user-entered text searches of your content.

Typically you use a fetched results controller to aid in your implementation of the table view datasource and delegate methods. Also, you create and use a fetch request for your fetched results controller. This is all boiler-plate (see the template code provided by Apple when you create a new project with the "Use Core Data for storage" option selected).

It is in the fetch request that you can create and specify a predicate. This will allow you to filter the objects that your table displays. For example: // only fetch objects with myAttribute set to someValue NSPredicate *pred = NSPredicate predicateWithFormat:@"myAttribute == %@",someValue; fetchRequest setPredicate:pred.

Well, I haven't mentioned clearly that I'm actually implementing a little search. I've already tried to set the predicate in the NSFetchedResultsController to filter the results, exactly like your posted code, but nothing happens, no objects are found. Any idea why the predicate doesn't work?

It's just a simple comparison between the search string and the objects name. Thanks for help – burki Feb 3 '10 at 20:07 You should add details about the predicate or ask a new question about it. Also, it's always good to show the code you are using when asking questions.

– gerry3 Feb 3 '10 at 20:49.

Great tutorial, although isn't relevant to the question regarding search. – Sam Soffes Feb 5 at 0:36 1 It was before the question was edited to provide more information – Grouchal Feb 8 at 10:33.

NSFetchedResultsController is used to work with tables;. Use NSFetchedResultsController.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions