SearchDisplayController does not display results if iphone is not English

I have a searchDisplayController that works great when searching for English and Arabic words using the method as follows:

 - (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope { NSString *query = self.searchDisplayController.searchBar.text; if (query && query.length) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ClientName contains[cd] %@", query]; [searchResultController_.fetchRequest setPredicate:predicate]; } NSError *error = nil; if (![[self searchResultController] performFetch:&error]) { // Handle error NSLog(@"Unresolved error %@, %@", error, [error userInfo]); exit(-1); // Fail } } 

However, this works fine if the iphone language is English, but if I changed the iPhone language to Arabic (global settings) and tried to search in Arabic or English, searchResultsController will not display the results, why?

ps when I put a static Arabic word in a query like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ClientName contains[cd] %@", @"تجريب"]; searchDisplayController display the correct Arabic word result تجريب

EDIT: I tried to build a predicate in the code as follows:

  NSExpression *clientNameEx=[NSExpression expressionForKeyPath:@"ClientName"]; NSExpression *aClientEx=[NSExpression expressionForConstantValue:query]; NSPredicate *predicate=[NSComparisonPredicate predicateWithLeftExpression:clientNameEx rightExpression:aClientEx modifier:NSDirectPredicateModifier type:NSContainsPredicateOperatorType options:0]; 

but to no avail ...

+6
source share
2 answers

I created a test project with Xcode 4, MasterDetail template, CoreData. Enabled and added the SearchBarController to the standard core views, added the UISearchBarDelegate delegate to the header, and clicked on the searchBarTextDidEndEditing method to invoke the search query.

 -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{ [NSFetchedResultsController deleteCacheWithName:nil]; self.fetchedResultsController = nil; [self.tableView reloadData]; } 

The final step was to add to fetchedResultsController:

 NSString *query = self.searchDisplayController.searchBar.text; if (query.length) { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"timeStamp contains[cd] %@", query]; NSLog(@"predicate %@", [predicate description]); [fetchRequest setPredicate:predicate]; } 

I turned on the Simulator iPhone and tested it with the iOS5 and Arabic settings. All search queries that successfully search for the word "test" and the word "تجريب" produce results. However, the word "تجريب" was copied from your question, as my arabica is a little rusty :). I also tried to make a record in the database with the first letter on the Arabic keyboard, and then search for it and get the result.

+1
source

I just found this article and it reminded me of your question. Perhaps you can use this solution?

+1
source

Source: https://habr.com/ru/post/905497/


All Articles