I have created a view with a tableview + searchbar. If searched for the first word in a string it works perfectly! Unfortunately it does not work if searched for a different word in the string. So if I would have an search for the text: bal.
And I would have the following string to look through: green bal. it would not find anything.
I currently am comparing the searchbar text with the data with this code:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
for (Product *product in self.listContent)
{
NSComparisonResult result = [product.name compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent product];
}
}
NSMutableSet *tempSet = [NSMutableSet setWithArray:self.filteredListContent];
self.filteredListContent = [NSMutableArray arrayWithArray:[tempSet allObjects]];
}
How can I solve this issue?
Any help or suggestions would be appreciated!
This code is looking for exact matches (insensitive to case as well as diacritics) using the
compare:options:range:method inNSString:Given your problem description, you wish to determine a string is contained inside another string. Use the
rangeOfString:options:method inNSStringinstead: