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 ...
随机推荐
- ASP.NET MVC5 高级编程 第3章 视图
参考资料<ASP.NET MVC5 高级编程>第5版 第3章 视图 3.1 视图的作用 视图的职责是向用户提供界面. 不像基于文件的框架,ASP.NET Web Forms 和PHP ,视 ...
- jQuery中$(function() {});问题详解
$(function() {});是$(document).ready(function(){ })的简写,最早接触的时候也说$(document).ready(function(){ })这个函数是 ...
- CentOS 6.4下通过YUM快速安装配置LAMP服务器(Apache+PHP5+MySQL)
准备篇: 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dp ...
- C#使用结构来传递多个参数
当参数超过5个时,建议用结构来传递多个参数. 示例代码如下: public struct MyStruct { public string str; public int number; } clas ...
- MessageBox详解
MessageBox.Show();可谓是winform开发中用的次数最多的东东啦.先贴一张msdn的图解 msdn好像没有更新哎,只提供了这几种方法,并且参数名称和最新的有差别,但实际上messag ...
- 《第一行代码--Android》阅读笔记之Activity
1.BaseActivity里面可以干什么 定义一个Context定义一个TAG 记录当前的Activity名字getClass().getSimpleName(); 2.Activity里面的几个重 ...
- oracle函数和存储过程示例
Function: --为了使产生的uuid符合rfc 4122的标准(http://tools.ietf.org/html/rfc4122),例如:a8f662b8-6e7a-13fe-e040-9 ...
- 4.0 流量控制preference
从Android4.0以后,系统设置应用程序允许用户查看他们的应用在前台和后台使用了多少网络数据.用户可以禁用每 个应用在后台使用网络数据.为了避免用户禁用你的应用在后台访问网络,你应该更效率的使用网 ...
- Delphi CxGrid 汇总(2)
17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...
- MVC中Model,不仅仅只是数据的传递者
在Model使用的时候很多人回向以前写三层架构一样使用它,将Model作为数据的传递者. 比如常见的写法 public int Id { get; set; } public int RoleId { ...