//
//  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的更多相关文章

  1. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  2. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  3. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  4. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  5. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  6. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  7. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  8. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

  9. UIKit 框架之Bar、Controller

    UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...

随机推荐

  1. linux查找日志常用命令

    1.查找文件test中目标字符串(xxxx)出现的行数位置grep -n xxxx  test 2.文件test从某一行(n)开始显示more +n  test 3.查询文件test中出现目标字符串x ...

  2. 鼠标HOVER时区块动画旋转变色的CSS3样式掩码

    鼠标hover时区块动画旋转变色的css3样式掩码<!DOCTYPE html> <html> <head> <meta charset="utf- ...

  3. CSS设计之页面滚动条出现时防止页面跳动的方法

    一.水平居中布局与滚动条跳动的千年难题 当前web届,绝大多数的页面间布局都是水平居中布局,主体定个宽度,然后margin: 0 auto的节奏~ 例如,大淘宝的首页: 然而,这种布局有一个存在一个影 ...

  4. Windows和Linux下Mysql 重置root 密码

    Windows系统下一:进入Windows窗口cmd命令行下,停止mysql服务: net stop mysql二:进入mysql的安装目录下,进去bin目录mysqld-nt.exe --skip- ...

  5. Linux下CPU占用率高分析方法

    一般解决方法是通过top命令找出消耗资源高的线程id,利用strace命令查看该线程所有系统调用1. 通过top命令找到可疑进程PID top - 09:37:18 up 70 days, 16:29 ...

  6. 在mac系统上安装Eclipse,编写java程序

    第一步:安装java jre(java 运行环境). 如图所示: 登陆Oralce官网,点击Download选项,找到如图所示界面: 选择Java Runtime Environment(JRE),打 ...

  7. PHP 文件上传服务端及客户端配置参数说明

    文件上传服务器端配置: ·file_uploads = On, 支持HTTP上传 ·upload_tmp_dir = , 临时文件保存的目录 ·upload_max_filesize=2M, 允许上传 ...

  8. php的register_shutdown_function函数详解

    function shutdown() { $last_error = error_get_last(); if ($last_error) { error_log(print_r($last_err ...

  9. 信驰达蓝牙4.0模块全面升级 v2.20 U最新发布

    作为国际蓝牙联盟成员之一,德州仪器(TI)于2012年强势推出CC254X系列单芯片(SOC)低功耗蓝牙收发器,经典51内核,最强优势在于丰富的外围(21个IO,UART,SPI,USB2.0,PWM ...

  10. SRF之数据验证

    实现表单输入数据的验证,包括客户端验证和服务器端验证 如何使用 数据验证在业务层的实体类字段上增加数据验证的特性,例如 public class User { [Required(ErrorMessa ...