I used the TableSearch sample from Apple to implement my own search in the app I'm working on.
It seems that the sample is bugged. The scope buttons will display the result controller only if something is entered in the search field. But, looking at the code, that doesn't seem the case because they specifically check for search items being empty or not:
if !searchItemsPredicate.isEmpty {
/** We have a scope type and other fields to search on -
so match up the fields of the Product object AND its product type.
*/
let compPredicate1 = NSCompoundPredicate(orPredicateWithSubpredicates: searchItemsPredicate)
let compPredicate2 = NSPredicate(format: "(SELF.type == %ld)", selectedScopeButtonIndex)
finalCompoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [compPredicate1, compPredicate2])
} else {
// Match up by product scope type only.
finalCompoundPredicate = NSCompoundPredicate(format: "(SELF.type == %ld)", selectedScopeButtonIndex)
}
So, if the search items predicate is empty (meaning nothing has been entered in the search field), the code is supposed to filter according to the product type. But that doesn't work when you run the app. However, if you just put a space into the search field, then the code filters the products correctly and displays the result controller. I've been trying to fix this but I haven't been able to find the relation between the content of the search field and the scope buttons.
Anybody has any idea?