@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. c++的一些陷阱(1)

    class String { public: String(]) { strcpy(p,pp); } ~String() { delete[] p; } char& operator[](in ...

  2. CSS编写技巧

    1.尽量少的使用全局的重置代码 全局重置代码:*{margin:0; padding:0;}对于熟悉CSS的人来说并不陌生,并且有很多人的第一句CSS代码就是这句.它可以避免不同浏览器的默认间距不同而 ...

  3. 如何同时运行两个tomcat?

    两个以上,要更改端口号.1 下载tomcat的压缩包(不是安装的那种,直接解压缩就能用的)下载地址:http://tomcat.apache.org/download-55.cgi 下载好的文件名是: ...

  4. iOS开发小技巧--iOS程序进入后台运行的实现

    iOS程序进入后台运行的实现 视频中看到老师用的iOS7,代码中有开启timer,无限请求数据的功能,但是切换到后台,代码就不打印了 自己用的iOS9,进入后台还是可以打印的,再次进入前台也可以正常运 ...

  5. Java研发方向如何准备BAT技术面试答案(上)

    http://blog.csdn.net/q979392157/article/details/52164319 阿里面试题总结 http://blog.csdn.net/q979392157/art ...

  6. 【BZOJ-2730】矿场搭建 Tarjan 双连通分量

    2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1602  Solved: 751[Submit][Statu ...

  7. Maven代理教程

    明确代理服务器地址及端口,比如proxy.supremehover.com:8080 找到maven目录下的conf\settings.xml并打开,在proxies节点下添加proxy <pr ...

  8. RabbitMQ 实现RPC

    实现RPC 首先要弄明白,RPC是个什么东西. (RPC) Remote Procedure Call Protocol 远程过程调用协议 在一个大型的公司,系统由大大小小的服务构成,不同的团队维护不 ...

  9. 动手实验iptables的NAT功能实现流量穿透

    1.NAT和iptables理论见: http://lustlost.blog.51cto.com/2600869/943110 2.引子 近期,有同事抱怨说数据入库时,由于数据库所在的服务器只有内网 ...

  10. 【Beta版本】七天冲刺集结令

    031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬涛 [Bet ...