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 ...
随机推荐
- JavaScript的理解记录(6)
---接上篇: 四.CSS相关: 1.CSS不支持注释// 支持注释/* */ 2. 几种浏览器厂商前缀: Firefox : -moz-; Chrome:-webkit- ; IE: ...
- ionic蓝牙用法
插件cordova官网cordova-plugin-ble-central 1.开启本机蓝牙 ble.enable( function() { console.log("Bluetooth ...
- gulp-rev-collector自定义修改rev-manifest.json后替换不成功的问题分析
由于项目需要,我要把common.js替换成build.min.js,接着后面才用到build.min.js=>build-te234ds.min.js这样的形式替换,但是我发现怎么替换都不能把 ...
- hdu2929 Bigger Is Better
题意 给出n根木棍,要你拼一个最大的数,并且这个数是m的倍数. 题解 显然越长的数越大.设\(dp[i][j]\)表示用i根木棍并且\(mod m = j\)的最大长度. 我们很容易想出dp方程,再用 ...
- 清除文件夹下的SVN信息
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Folder/shell/清除SVN信息] @=&q ...
- IIS错误处理集合
1.编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ya ...
- C# Httpclient编程
今天研究了一天C#如何添加cookie到httpcient里面,从而发请求时,能把cookie作为头部发出,最后发现根本加不进去. Httpclient的cookie是来自上一个请求的响应,httpc ...
- lodop打印控件
http://www.c-lodop.com/demolist/PrintSampIndex.html
- 统计SqlServer每张表内的数据量
CREATE TABLE #temp (TableName VARCHAR (255), RowCnt INT)EXEC sp_MSforeachtable 'INSERT INTO #temp SE ...
- jQuery知识点一 each()和toggleClass()
jQuery的一些东东比较容易忘,所以在这里整理一下... ... 1. each (1) $(selector).each(function(index,element)) inde ...