原创Blog,转载请注明出处
blog.youkuaiyun.com/hello_hwc
前言:
本文是Demo的第一阶段,简单的讲解如何使用UISearchController进行tableview搜索。下一篇文章会在这个基础上深一步讲解更多的代理函数和Tableview的使用。本文源代码只提供OC版本,下一篇我会提供OC和Swift两个版本。
Demo效果
最简单的按照前缀来搜索
一 UISearchController
这是一个提供了SearchBar的Controller,继承自UIViewController。使用它提供的SearchBar做为用户输入,使用它的代理函数来实时处理用户输入的事件,并且把结果返回给resultViewController。
初始化
这里的searchResultsController负责显示搜索后的结果
- (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController
SearchBar
@property(nonatomic, retain, readonly) UISearchBar *searchBar
searchResultsUpdater
负责更新resultViewController的对象,必须实现UISearchResultsUpdating协议
@property(nonatomic, assign) id< UISearchResultsUpdating > searchResultsUpdater
dimsBackgroundDuringPresentation
展示的时候,背景变暗。如果是在同一个view 中,则设为NO。默认为YES。
@property(nonatomic, assign) BOOL dimsBackgroundDuringPresentation
hidesNavigationBarDuringPresentation
是否隐藏导航栏,默认为YES。
@property(nonatomic, assign) BOOL hidesNavigationBarDuringPresentation