views:

549

answers:

1

Hey!

I'm creating a simple Navigation-based app using core data for my iPhone and I'm trying to implement a little search. The app is baed on the "Navigation-based application"-template from Apple. The NSFetchedResultsController gets all the objects and they will be displayed in the table view. I've also have left the Plus button to add new objects. Well, I've implemented a UISearchBar and a UISearchDisplayController, both in the same. The search uses the same NSFetchedResultsController to filter the objects. An NSPredicate will be set in the UISearchDisplayController Delegate methods, but it seems that the predicate hasn't been set, because the fetchedResultsController doesn't filter anything. That's my first problem. Now, if I press the cancel button of the search bar and want to insert a new object by pressing the plus button, it doesn't go. No objects will be inserted, an the app doesn't crash, it just happens nothing.

Do I have to use two different NSFetchedResultsController in one single view? If yes, this doesn't solve the problem why the NSPredicate isn't set. I already thank you for your help.

+2  A: 

If you modify your fetch request (such as by changing the predicate), you need to create a new fetched results controller.
Alternatively, you could access your fetched objects as an array (using the fetchedObjects property of the fetched results controller) and filter that array based on the search criteria. This has the added benefit of aligning more with Apple's sample code for table search (since they use an array to back the table view).

gerry3