@property (nonatomic, strong)  UISearchController* searchController;

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.delegate=self;
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
// self.searchController.searchBar.backgroundColor=[UIColor blueColor];
//frame=CGRectMake(0, 0, ScreenWidth, 44);
self.searchController.searchBar.layer.borderColor=[[UIColor colorWithHex:0xEEEEEE] CGColor];
self.searchController.searchBar.layer.borderWidth=0.5;
self.searchController.searchBar.barTintColor=[UIColor colorWithHex:0xEEEEEE];
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView=self.searchController.searchBar; - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = self.searchController.searchBar.text;
[self.peopleSearchData removeAllObjects];
// UserModel *model = self.peopleData[indexPath.section][indexPath.row];
for (NSArray *modelarray in self.peopleData) {
for (UserModel *model in modelarray) {
NSRange range1 = [model.nickName rangeOfString:searchString];
NSRange range2 = [model.company rangeOfString:searchString];
if ((range2.length != ||range1.length != )&&![model.name isEqualToString:@"NO_Section=0"]) { //range1.location != NSNotFound
[self.peopleSearchData addObject:model];
}
}
// BOOL range = [model.name hasPrefix:searchString];
}
if (_peopleSearchData.count!=) {
_tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
}else{
_tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
}
[self.tableView reloadData];
} - (void)willPresentSearchController:(UISearchController *)searchController{ } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
[self.searchController.searchBar resignFirstResponder];
NSLog(@"scrollViewWillBeginDragging");
} - (void)didPresentSearchController:(UISearchController *)searchController{
UIButton *cancelButton = nil;
UIView *topView = self.searchController.searchBar.subviews[];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
}
}
if (cancelButton) {
//Set the new title of the cancel button
// [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor colorWithHex:0x31425E] forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont fontWithName:@"Heiti SC" size:];
}
} // 搜索框开始编辑时触发方法
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[self presentViewController:self.searchController animated:YES completion:nil];
}
if (self.searchController.active) {
self.searchController.active = NO;
[self.searchController.searchBar removeFromSuperview];
}

UItableview 添加 uisearchController的更多相关文章

  1. UITableView与UISearchController搜索及上拉加载,下拉刷新

    #import "ViewController.h" #import "TuanGouModel.h" #import "TuanGouTableVi ...

  2. 在Storyboard中为UITableView添加Header和Footer

    我在这里所说的Header和Footer并不是sectionHeader和sectionFooter,而是指UITableView的tableHeaderView和tableFooterView,这两 ...

  3. [iOS]swift之UITableView添加通过xib创建的headerView坑爹问题

    情景是这样的,我UITableView添加了一个HeaderView,这个HeaderView是通过xib创建,是UIView.出来的结果却出乎意料,UITableView的Cell最顶部的几个被He ...

  4. iOS 疑难杂症 — — UITableView 添加 tableFooterView 旋转屏幕后收不到点击事件!!!

    声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 新手的烦恼你不懂 - - ## ...

  5. Swift - 给表格UITableView添加索引功能(快速定位)

    像iOS中的通讯录,通过点击联系人表格右侧的字母索引,我们可以快速定位到以该字母为首字母的联系人分组.   要实现索引,我们只需要两步操作: (1)实现索引数据源代理方法 (2)响应点击索引触发的代理 ...

  6. iOS 7.1 UITableView添加footerView 后 最后一行分割线无法显示

    今天用故事版 遇到个奇怪的问题: 我要用 tbView(tableView)展示写信息.最后一行我要显示些文案什么的.考虑用 footerView ,开心coding ..,show下 哪里有些不对吧 ...

  7. UITableView添加静态背景.

    1:  controller self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@" ...

  8. UIView UITableView 背景图片添加

    这几天,经常用到为某个视图设置背景图片,而API中UIView没有设置背景图片的方法,搜集归纳如下: 第一种方法: 利用的UIView的设置背景颜色方法,用图片做图案颜色,然后传给背景颜色. UICo ...

  9. iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

随机推荐

  1. javascript 中断函数的使用 setInterval();

    <script type="text/javascript"> var i=1; var IR1 = setInterval("myMethod()" ...

  2. qq菜单的折叠与展示

    敲出每个小例子是一种进步 html结构: <body> <ul id="list"> <li class="lis"> &l ...

  3. maven-各配置文件详解

    1.setting.xml http://www.cnblogs.com/yangxia-test/p/4409736.html <?xml version="1.0" en ...

  4. Thinking in java学习笔记之迭代器

    Map<String,String> map = new HashMap<String,String>(); List list = new ArrayList(); list ...

  5. ios开发网络知识 TCP,IP,HTTP,SOCKET区别和联系

    TCP,IP,HTTP,SOCKET区别和联系 网络由下往上分为:        对应 物理层-- 数据链路层-- 网络层--                       IP协议 传输层--     ...

  6. php.ini 中文注释

    这个文件控制了PHP许多方面的观点.为了让PHP读取这个文件,它必须被命名为 ; ´php.ini´.PHP 将在这些地方依次查找该文件:当前工作目录:环境变量PHPRC ; 指明的路径:编译时指定的 ...

  7. My97DatePicker

    http://www.my97.net/index.asp <input id="txtDate" class="Wdate" type="te ...

  8. html5 新选择器 querySelector querySelectorAll

    querySelector 返回满足条件的单个元素 使用实例 HTML <div id="main">主体布局</div> JS var main =doc ...

  9. 关于Hibernate5.x的那点事

    1.如果采用程序建表: 4.x版本: Configuration cfg = new Configuration().configure(); SchemaExport se = new Schema ...

  10. 最终解决 mouseenter, mouseleave , mouseout mousehover mousemove等事件的区别?

    在jquery中, html页面的div的显示和隐藏, 修改等的功能, 最终都要由 事件 触发来引用, 不管是键盘事件, 还是鼠标事件... mouseenter和mouseleave是成对对应的, ...