UIKit 框架之UISearchController
//
// tableViewController.m
// searchController
//
// Created by City--Online on 15/6/1.
// Copyright (c) 2015年 CYW. All rights reserved.
//
#import "tableViewController.h"
@interface tableViewController ()<UISearchResultsUpdating,UISearchControllerDelegate>
@property(nonatomic,strong) NSArray *allData;
@property(nonatomic,strong) NSMutableArray *searchData;
@end
@implementation tableViewController
- (void)viewDidLoad {
[super viewDidLoad];
_allData=@["];
_searchData=[_allData mutableCopy];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(search )];
self.tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
}
-(void)search
{
// 为nil时是其本身
UISearchController *searchvc=[[UISearchController alloc]initWithSearchResultsController:nil];
searchvc.searchBar.tintColor=[UIColor orangeColor];
searchvc.searchBar.barTintColor=[UIColor redColor];
searchvc.definesPresentationContext=YES;
searchvc.hidesNavigationBarDuringPresentation=NO;
[searchvc.searchBar sizeToFit];
searchvc.searchResultsUpdater=self;
searchvc.delegate=self;
[self presentViewController:searchvc animated:YES completion:nil];
}
//搜索栏文本内容改变时触发 和下面的
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSLog(@"aaa%@",searchController.searchBar.text);
) {
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"SELF CONTAINS %@",searchController.searchBar.text];
_searchData=[[_allData filteredArrayUsingPredicate:predicate] copy];
}
[self.tableView reloadData];
}
//搜索视图将要消失时触发
-(void)willDismissSearchController:(UISearchController *)searchController
{
NSLog(@"%@",searchController.searchBar.text);
) {
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"SELF CONTAINS %@",searchController.searchBar.text];
_searchData=[[_allData filteredArrayUsingPredicate:predicate] copy];
}
else
{
_searchData=[_allData mutableCopy];
}
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _searchData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text=[_searchData objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",indexPath);
}
@end



UIKit 框架之UISearchController的更多相关文章
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
- UIKit 框架之Bar、Controller
UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...
随机推荐
- 支持在安卓中UI(View)的刷新功能
这是一款可以支持在安卓中UI(View)的刷新功能,Android中对View的更新有很多种方式,使用时要区分不同的应用场合.我感觉最要紧的是分清:多线程和双缓冲的使用情况. 现在可以尝试理解下 ...
- 两分钟让你明白什么是ERP
把专业的问题通俗化—— ERP(Enterprise Resource Planning)企业资源计划系统,是指建立在信息技术基础上,以系统化的管理思想,为企业决策层及员工提供决策运行手段的管理 ...
- 查看软、硬raid信息的方法
软件raid:只能通过Linux系统本身来查看cat /proc/mdstat可以看到raid级别,状态等信息. 硬件raid:最佳的办法是通过已安装的raid厂商的管理工具来查看,有cmdline, ...
- linu流量监控
iftophttp://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858923.html 默认是监控第一块网卡的流量iftop 监控eth1iftop ...
- 两个和尚抬水有水喝,三个和尚抬水没水喝------IT项目管理之组织架构
说到项目经理岗位,一般的想法是,一个项目只能有一个项目经理,否则责任不明,互相推诿.偏偏IT项目需要有两个甚至三个项目经理.原因何在呢? 典型的IT项目(不包含纯技术或工具类项目)是把用户的需求转化成 ...
- Winform登录、控制软件只运行一次、回车登录
Winform登录对很多程序猿来说都有些困惑,登录进入主窗体后要销毁登录窗体,而不是隐藏哦,怎么实现呢? 先贴一段Program.cs的代码 static void Main() { Mutex mu ...
- jquery 基础汇总---导图篇
最近在慕课网学习了一些jquery的基础知识,为了方便记忆,整理出来的导图 jQuery基础总共分为4个部分,分别是样式篇.事件篇.动画篇.DOM篇. 样式篇,主要介绍jQuery的基础语法,选择器以 ...
- 在Spark中使用Kryo序列化
spark序列化 对于优化<网络性能>极为重要,将RDD以序列化格式来保存减少内存占用. spark.serializer=org.apache.spark.serializer.Jav ...
- 操作MySQL数据库
向表中插入数据 insert 语句可以用来将一行或多行数据插到数据库表中, 使用的一般形式如下: insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, ...
- Java 中的构造方法
首先创建一个Transport类,定义好类的属性和方法,并且写好构造方法,先看下无参数的构造方法: public class Transport { //名字 public String name; ...