UISearchDisplayController/NSFetchedResultsController with custom sort order
I'm implementing a search feature in my app. I would like the user to look up a word simultaneously in multiple attributes of a given Entity.
Here is an example for an Entity with 3 String attributes: Person (firstName, lastName, notes)
Let's use a mock dataset with 3 people:
Now, let's assume the user is looking up the occurence "will" and that we run a case insensitive search. All three previously described people will match the word "will" thanks to the use of an orPredicateWithSubpredicates
Ideally I would like the results to be displayed in this order for relevancy purposes:
For this search feature "firstName" is more relevant than "lastName" which are both more relevant than the "notes" attribute.
Since I'm using a UISearchDisplayController, I also use an NSFetchedResultsController which requires an NSSortDescriptor . The problem for me now is what attribute/key I am going to use to init the NSSortDescriptor?
I've been through many posts already and thought a transient property could help me with this issue, but I can't figure out how/when to set up this transient property which could be named something like "sortKey" and be set to these values:
Eventually I guess I could try to run three different requests but then I'd have to give up using NSFetchedResultsController and all its magic...
I don't know whether I'm hitting the limits of NSFetchedResultsController or something but any pointer would be great, thanks!
Joss.
链接地址: http://www.djcxy.com/p/6138.html上一篇: 使用to来排序NSFetchedResultsController
下一篇: UISearchDisplayController / NSFetchedResultsController具有自定义排序顺序