UItableview 添加 uisearchController
@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的更多相关文章
- UITableView与UISearchController搜索及上拉加载,下拉刷新
#import "ViewController.h" #import "TuanGouModel.h" #import "TuanGouTableVi ...
- 在Storyboard中为UITableView添加Header和Footer
我在这里所说的Header和Footer并不是sectionHeader和sectionFooter,而是指UITableView的tableHeaderView和tableFooterView,这两 ...
- [iOS]swift之UITableView添加通过xib创建的headerView坑爹问题
情景是这样的,我UITableView添加了一个HeaderView,这个HeaderView是通过xib创建,是UIView.出来的结果却出乎意料,UITableView的Cell最顶部的几个被He ...
- iOS 疑难杂症 — — UITableView 添加 tableFooterView 旋转屏幕后收不到点击事件!!!
声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 新手的烦恼你不懂 - - ## ...
- Swift - 给表格UITableView添加索引功能(快速定位)
像iOS中的通讯录,通过点击联系人表格右侧的字母索引,我们可以快速定位到以该字母为首字母的联系人分组. 要实现索引,我们只需要两步操作: (1)实现索引数据源代理方法 (2)响应点击索引触发的代理 ...
- iOS 7.1 UITableView添加footerView 后 最后一行分割线无法显示
今天用故事版 遇到个奇怪的问题: 我要用 tbView(tableView)展示写信息.最后一行我要显示些文案什么的.考虑用 footerView ,开心coding ..,show下 哪里有些不对吧 ...
- UITableView添加静态背景.
1: controller self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@" ...
- UIView UITableView 背景图片添加
这几天,经常用到为某个视图设置背景图片,而API中UIView没有设置背景图片的方法,搜集归纳如下: 第一种方法: 利用的UIView的设置背景颜色方法,用图片做图案颜色,然后传给背景颜色. UICo ...
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
随机推荐
- 如何对多个属性进行transform
w3school对transform的介绍很简单 transform: none|transform-functions; transform的默认值是none 其所举的例子也只是对一个值进行过渡,其 ...
- BZOJ 1005 [HNOI2008] 明明的烦恼(组合数学 Purfer Sequence)
题目大意 自从明明学了树的结构,就对奇怪的树产生了兴趣...... 给出标号为 1 到 N 的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树? Input 第一行为 N( ...
- 【OpenJudge 191】【POJ 1189】钉子和小球
http://noi.openjudge.cn/ch0405/191/ http://poj.org/problem?id=1189 一开始忘了\(2^{50}\)没超long long差点写高精度Q ...
- c# cache 缓存
System.Web.Caching简介 /// <summary> /// 创建随机字符串 /// </summary> /// <returns></re ...
- javascript学习
代码放在E:\JS\js学习 学习中要学会多查手册 javascript基本介绍 js是用于web开发的脚本语言. 后面统称为 js 脚本语言是什么? 脚本语言不能独立使用,它和html/jsp/ph ...
- HTTP协议—— 简单认识TCP/IP协议
大学没读计算机专业,所以很多的专业知识都不知道.既然已经从事了IT这个行业,就势必要去了解下网络底层,虽然实际工作中这些东西用不到.高楼大厦,起于平川.不积跬步,无以至千里,不积小流,无以成江海.我现 ...
- 常用的网络命令--之...... Ipconfig详解
ipconfig是运行微软的Windows9x/NT/2000/XP/Vista操作系统的电脑上用来控制网络连接的一个命令行工具.它的主要功用,包括用来显示现时网络连接的设置(/all参数),或通过/ ...
- 11月1日上午PHP批量删除
1.在主页面上添加批量删除有关代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- C++箴言:理解typename的两个含义
C++箴言:理解typename的两个含义 问题:在下面的 template declarations(模板声明)中 class 和 typename 有什么不同? template<class ...
- 如何删除xcode项目中不再使用的图片资源
1. 利用工具 下载地址 http://jeffhodnett.github.io/Unused/ 运行效果如下 2. 通过终端 执行 shell 命令 a. 第一步建立.sh 文件 如 ...