如何基于从iOS开始的字符执行搜索 [英] How to perform searching based on characters starting in ios

查看:51
本文介绍了如何基于从iOS开始的字符执行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好在我的ipad应用程序中正在使用搜索栏执行搜索操作.要执行此搜索操作,我正在使用以下逻辑

Hi in my ipad application am performing searching operation using searchbar.For performing thise searching operation i am using following logic

  1. 如果任何元素包含我要在搜索栏中输入的字符,则这些元素必须从那么多元素中提取并显示在表格中.

代码:

NSRange rTextRange = [finalSearchingString rangeOfString:searchStr options:(NSCaseInsensitiveSearch)];`
if (range.location != NSNotFound){                                       
     [self.filterdList addObject:product];
}

在这里,最终结果在filterdList数组中可用,并且该数组数据我将在表视图中显示.

here final results avaialble in filterdList array and that array data i will display in tableview.

现在我在此操作中遇到的问题实际上是现在需求已更改.新要求是从搜索字符开始的产品,这些字符仅需显示不包括的产品.请帮助我如何实现此功能.谢谢.

Now my issue in this operation is actually now the requirement is changed. New requirement is The product which are starting with searching characters those only have to display not included products. Please help me how to implement this functionality .Thanks in advance.

推荐答案

尝试这样,希望这一点对您有所帮助,

try like this i Hope this one helps you,

   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",  txtSearch.text];
   NSArray *ResultArray = [yourArray filteredArrayUsingPredicate:predicate];
  [tableview reloadData];

将以上代码保留在searchBar委托方法中,并使用结果数组重新加载tableview.

kept above code in searchBar delegate method and reload the tableview with result array.

这篇关于如何基于从iOS开始的字符执行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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