iOS-UISearchBar和UISearchController(参考网友来练习一下)
#import "ViewController.h"
#import "TestCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchResultsUpdating>
{
NSMutableArray *dataArray;
NSMutableArray *searchArray;
UISearchController *mySearchController; }
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; mySearchController=[[UISearchController alloc]initWithSearchResultsController:nil];
mySearchController.searchResultsUpdater=self;
mySearchController.dimsBackgroundDuringPresentation=NO;
mySearchController.hidesNavigationBarDuringPresentation=NO;
mySearchController.searchBar.frame=CGRectMake(mySearchController.searchBar.frame.origin.x, mySearchController.searchBar.frame.origin.y, mySearchController.searchBar.frame.size.width, 44.0 );
self.myTableView.tableHeaderView=mySearchController.searchBar; dataArray=[NSMutableArray array];
for(NSInteger i=;i<;i++)
{
[dataArray addObject:[NSString stringWithFormat:@"%ld-test",(long)i]];
} } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (mySearchController.active)
{
return searchArray.count;
}
else
{
return dataArray.count;
} }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TestCell *testCell=[tableView dequeueReusableCellWithIdentifier:@"TestCell" forIndexPath:indexPath];
if (mySearchController.active) {
testCell.testLabel.text=searchArray[indexPath.row];
}
else
{
testCell.testLabel.text=dataArray[indexPath.row];
} return testCell;
}
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString=mySearchController.searchBar.text;
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"self contains[c]%@",searchString];
if (searchArray.count)
{
[searchArray removeAllObjects];
}
searchArray=[NSMutableArray arrayWithArray:[dataArray filteredArrayUsingPredicate:predicate]];
[_myTableView reloadData]; }
@end
iOS-UISearchBar和UISearchController(参考网友来练习一下)的更多相关文章
- 《招聘一个靠谱的iOS》面试题参考答案(下)
相关文章: <招聘一个靠谱的iOS>面试题参考答案(上) 说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外 ...
- iOS UISearchBar UISearchController
搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社 交,O2O还是在线教育等都会有一个搜索栏的实现,不过彼此实现效果是 ...
- iOS开发-搜索栏UISearchBar和UISearchController
iOS中UISearchDisplayController用于搜索,搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社 ...
- [转] iOS开发-搜索栏UISearchBar和UISearchController
原文网址: http://www.cnblogs.com/xiaofeixiang/p/4273620.html?utm_source=tuicool iOS中UISearchDisplayContr ...
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- 招聘一个靠谱的iOS》面试题参考答案(上)
说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均为简答题. 博文中给出了高质量的面试题,但是未给出答案, ...
- 《招聘一个靠谱的iOS》面试题参考答案(上)
说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均为简答题. 博文中给出了高质量的面试题,但是未给出答案, ...
- ios UISearchBar搜索框的基本使用
摘要: 小巧简洁的原生搜索框,漂亮而易用,如果我们的应用没有特殊需求,都可以使用它. iOS中UISearchBar(搜索框)使用总结 初始化:UISearchBar继承于UIView,我们可以像创建 ...
- iOS UISearchBar 设置取消按钮,回收键盘,并修改cancel为“取消”
继承协议: UISearchBarDelegate 在代理方法中设置: #pragma mark --- 搜索框开始编辑 --- - (void)searchBarTextDidBeginEditin ...
随机推荐
- 前端异步解决方案——mmDeferred
Deferred是前端解决异步操作的一种编程范式,后来出现的Promise规范更是让其普适性大大提高.不过Promise规范也存在分岐.现在最流行的是Promise/A规范. Promise/A大致是 ...
- labview事件结构
等待事件发生,并执行相应条件分支,处理该事件.事件结构 包括一个或多个子程序框图或事件分支,结构处理时间时,仅有一个子程序框图或分支在执行.等待事件通知时,该结构可超时. 连线边框左上角的“超时”接线 ...
- hdu 1176 免费馅饼(数塔类型)
http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Windows 7 不同安装模式简要区别(图解)
★ 你可能对GHOST不支持AHCI感到迷惑,实际上,写过GHOST一键安装批处理的都知道一个叫FINDCD.EXE的小程序,可是这个程序老 了,AHCI模式光驱他找不到了,找不到光驱动意味着光盘中G ...
- emWin(ucGui) MULTIEDIT控件的按键响应处理 worldsing
目前没有读过ucgui的源代码,通过应用代码测试出在FRAMEWIN的控件焦点顺序是样的: 按资源列表里创建的控件,默认将焦点落在第一个可接收焦点的控件,目前知道不可接收 焦点的控件有TEXT,在FR ...
- [置顶] 如何在浏览器中打开PDF文件并实现预览的思路与代码
编写项目遇到一个需要在浏览器中打开PDF文件的问题.最终实现效果如下: 其实也就是简单的在浏览器中实现一个打开pdf文件,并有类似预览功能的边框. 其实在网上经常见到类似的页面,在浏览器中打开pdf文 ...
- [置顶] EASYUI+MVC4+VS2010通用权限管理系统开发
通用权限案例平台在经过几年的实际项目使用,并取得了不错的用户好评.在平台开发完成后,特抽空总结一下平台知识,请各位在以后的时间里,关注博客的更新. 1.EASYUI+MVC4通用权限管理平台--前言 ...
- Spring REST实践之Spring Web MVC
Spring概要 Spring Framework提供了依赖注入模型和面向切面编程,简化了基础型代码的编写工作以及更好的能够与其它框架和技术整合起来.Spring Framework由data acc ...
- WSO2 Stratos手册
WSO2 Stratos是最完整的企业级cloud solution,提供了一个开放的PaaS平台,相比于其他的PaaS平台来说,Stratos支持更多核心的服务.Stratos2.0对那些想从异构环 ...
- 分享一个导出Excel时页面不跳转的小技巧
今天在点击客户档案导出的时候,发现先是打开了一个新标签,然后新标签自动关掉,弹出一个文件下载确认的窗口,点击确认后开始下载导出的Excel文件.这样的过程感觉窗口闪来闪去,而且可能会给用户带来困惑,是 ...
#import "ViewController.h"