Dynamic display of list while using search bar in ipad
I am creating an app in which i am using a dictionary with quite a large number of words.Now i am creating a Search bar and that will be 开发者_StackOverflowused to input the word which i will be looking in the dictionary.Actually this plan is accomplished with the below code but now what i want is that whenever i write a sentence say "Daddy drinks juice " then the list should display me all the permutations and combinations,i mean to say it must display all the three words individually ,then it must display sentences which will contain any of the words i entered like :- she DRINKS water,lime JUICE,mommy and DADDY and other sentences which will contain these words either individually or in combination.
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfItems)
{
NSArray *array = [dictionary objectForKey:@"Words"];
[searchArray addObjectsFromArray:array];
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray release];
searchArray = nil;
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"( %K contains[cd] %@ ) OR ( %K contains[cd] %@ ),yourfirstKey,searchText];
NSArray * filteredArray = [searchArray filteredArrayUsingPredicate:predicate];
Hope this helps
精彩评论