UISearchBar学习的一些杂记

把书本的代码敲下来,发现搜索的实现就那么几行代码,感叹强大之余,也挺伤脑,一下子太多新东西,又是NSPredicate的、又是NSRange的。。。

下面是两个委托方法,其实还不是很明白,过几天回来看看,或许有新发现。哈哈。


#pragma mark -
#pragma mark Search Display Delegate Methods
- (void)searchDisplayController:(UISearchDisplayController *)controller
  didLoadSearchResultsTableView:(UITableView *)tableView
{
    [tableView registerClass:[UITableViewCell class]
      forCellReuseIdentifier:SectionsTableIdentifier];
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
    [filteredNames removeAllObjects];
    if (searchString.length > 0) {
        NSPredicate *predicate =
        [NSPredicate
         predicateWithBlock:^BOOL(NSString *name, NSDictionary *b)
         {
             //返回name中与searchString匹配的首个串的范围,options指定搜索选项(这个先放放)
             NSRange range = [name rangeOfString:searchString
                                         options:NSCaseInsensitiveSearch];
             return range.location != NSNotFound;
         }];
        
        for (NSString *key in self.keys) {
            //按照谓词predicate的规则过滤self.name[key]
            NSArray *matches = [self.names[key]
                                filteredArrayUsingPredicate: predicate];
            [filteredNames addObjectsFromArray:matches];
        } }
    return YES;
}


关于options,官方文档直接google翻译:

搜索和比较选项

几个搜索和比较的方法,采取“选项”的说法。这是一个位掩码,进一步增加了限制的操作。您通过结合下列选项(并非所有选项都可供每一个方法)创建蒙版:

搜索选项

效果

NSCaseInsensitiveSearch

忽略大小写字符之间的区别。

NSLiteralSearch

执行一个字节为字节的比较。不同的文字序列(如组成的字符序列),否则将被视为等同被视为不匹配。使用此选项可以加快一些操作显着。

NSBackwardsSearch

从端部朝向开始的范围内执行搜索。

NSAnchoredSearch

执行搜索只在字符的开头或如果NSBackwardsSearch也被指定范围的结束。在开头或结尾的不匹配意味着没有被发现,即使匹配的字符序列,字符串中的其他地方发生。

NSNumericSearch

当使用比较:选项:方法,组数字被视为一个数值比较的目的。例如,Filename9.txt < Filename20.txt <Filename100.txt

正在执行搜索和比较,如果的NSLiteralSearch选项指定。


原文:

Search and Comparison Options

Several of the search and comparison methods take an “options” argument. This is a bit mask that adds further constraints to the operation. You create the mask by combining the following options (not all options are available for every method):

Search option

Effect

NSCaseInsensitiveSearch

Ignores case distinctions among characters.

NSLiteralSearch

Performs a byte-for-byte comparison. Differing literal sequences (such as composed character sequences) that would otherwise be considered equivalent are considered not to match. Using this option can speed some operations dramatically.

NSBackwardsSearch

Performs searching from the end of the range toward the beginning.

NSAnchoredSearch

Performs searching only on characters at the beginning or, if NSBackwardsSearch is also specified, the end of the range. No match at the beginning or end means nothing is found, even if a matching sequence of characters occurs elsewhere in the string.

NSNumericSearch

When used with the compare:options: methods, groups of numbers are treated as a numeric value for the purpose of comparison. For example, Filename9.txt < Filename20.txt < Filename100.txt.

Search and comparison are currently performed as if the NSLiteralSearch option were specified.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Three.js是一款基于WebGL的JavaScript 3D引擎,可以用于开发VR应用程序。使用Three.js创建VR应用程序的简单步骤包括学习Three.js的基本知识,了解WebVR API,以及使用Three.js的相机控件OrbitControls来控制视角。\[1\]\[2\]\[3\] 你可以通过学习Three.js中文教程和相机控件的文档来深入了解和使用Three.js进行VR开发。 #### 引用[.reference_title] - *1* [Three.js如何创建VR应用程序](https://blog.csdn.net/baidu_29701003/article/details/129805443)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Three.js杂记(七)—— VR全景效果制作·上(含python爬虫偷碎图,canvas重组图片)](https://blog.csdn.net/qq_36171287/article/details/112438341)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Three.js初体验——VR全景展示](https://blog.csdn.net/kitty_ELF/article/details/118571576)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值