在ipad中使用搜索栏时动态显示列表 [英] Dynamic display of list while using search bar in ipad

查看:116
本文介绍了在ipad中使用搜索栏时动态显示列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我正在使用包含大量单词的字典.现在我正在创建搜索栏,并将其用于输入要在字典中查找的单词.计划是用下面的代码完成的,但是现在我想要的是,每当我写一个句子说爸爸喝果汁"时,列表就应该显示所有排列和组合,这意味着必须分别显示所有三个单词,然后它必须显示包含我输入的任何单词的句子,例如:-她喝水,石灰汁,妈妈和DADDY,以及包含这些单词的单独或组合单词的其他句子.

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 used 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];

希望这会有所帮助

这篇关于在ipad中使用搜索栏时动态显示列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆