美文网首页
UISearchViewController

UISearchViewController

作者: 何小八 | 来源:发表于2017-10-13 16:10 被阅读0次

简单使用

1、定义属性

@property (nonatomic, strong) CMemberSearchResultController *resultVC; //自定义的SearchResultsController
@property (nonatomic, strong) UISearchController *searchC;

2、初始化CMemberSearchResultController和UISearchController

self.resultVC = [CMemberSearchResultController new];
self.searchC = [[UISearchController alloc] initWithSearchResultsController:self.resultVC];
self.searchC.searchResultsUpdater = self.resultVC;  //protocal协议,这个我们让self.resultVC去处理
self.searchC.searchBar.placeholder = @"搜索";
self.searchC.hidesNavigationBarDuringPresentation = NO; //当present的时候是否隐藏navigationBar;当为NO的时候,点击searchBar,searchBar不会上移到顶部
self.definesPresentationContext = YES; //当present的时候,navigationBar上的子控件时候渲染
[view addSubview: self.searchC.searchBar];

注意点

创建UISearchControllerSearchResultsController的时候,必须用强引用(属性或成员变量),不能用弱引用(临时变量),不然没有系统的效果

相关文章

网友评论

      本文标题:UISearchViewController

      本文链接:https://www.haomeiwen.com/subject/ybizyxtx.html