搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UIS)

1.在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISearchDisplayController的组合方式.

2.在使用UISearchController前先定义以下属性

//定义一个UISearchController
@property (nonatomic,strong) UISearchController *searchController;
//用来展示搜索结果
@property (nonatomic,strong) ResultViewController *resultVC;
//用来接收searchController搜索出来的结果
@property (nonatomic,strong) NSMutableArray *searchArr;
//开辟空间,用来接受搜索出来的结果
_searchArr = [[NSMutableArray alloc] init];
//实例化searchController
_searchController = [[UISearchController alloc] initWithSearchResultsController:_resultVC];
//设置搜索更新时调用的代理
_searchController.searchResultsUpdater = self;
//设置搜索框,自适应,否则搜索框无法显示
[_searchController.searchBar sizeToFit];
//将搜索框添加到tableView上
[_tableView addSubview:_searchController.searchBar];
//以下属性感觉设置跟没设置没啥差别
//设置开始搜索时背景显示与否
_searchController.dimsBackgroundDuringPresentation = NO;
//搜索时,背景变暗色
_searchController.dimsBackgroundDuringPresentation = NO;
//搜索时,背景变模糊
_searchController.obscuresBackgroundDuringPresentation = NO;
//隐藏导航栏
_searchController.hidesNavigationBarDuringPresentation = NO;

  

UISearchController的更多相关文章

  1. UISearchController 的用法[点击搜索框,自动到顶部]

    //在ViewDidLoad里面如下代码 self.searchViewController = [[UISearchController alloc]initWithSearchResultsCon ...

  2. iOS UISearchController的使用

    在iOS9中,UISearchDisplayController 已经被UISearchController替代.搜索框是一种常用的控件. 假设我们要满足下图的需求,产生100个“数字+三个随机字母” ...

  3. iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

  4. UISearchController使用

    iOS8之前我们使用UISearchDisplayController做TableView的本地搜索 iOS8提供实现搜索功能的SDK:UISearchController(iOS8.0之后).UIS ...

  5. UItableview 添加 uisearchController

    @property (nonatomic, strong) UISearchController* searchController; self.searchController = [[UISear ...

  6. UITableView与UISearchController搜索及上拉加载,下拉刷新

    #import "ViewController.h" #import "TuanGouModel.h" #import "TuanGouTableVi ...

  7. iOS原生的搜索:UISearchController

    iOS8之前我们使用UISearchDisplayController做TableView的本地搜索,查看UIKit库,苹果已经使用新控件取代它. NS_CLASS_DEPRECATED_IOS(3_ ...

  8. UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior

    Attempting to load the view of a view controller while it is deallocating is not allowed and may res ...

  9. iOS8以后 UISearchController的用法

    查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面): 1. 声明属性 @property (nonatomic, strong) UISearchController ...

随机推荐

  1. redis学习之二from github

    大概敲了一遍基本命令,熟悉了redis的存储方式.现在开始进一步系统的学习.学习教程目前计划有三个,一个是github上的https://github.com/JasonLai256/the-litt ...

  2. Auto Mapper02《demo》

         学习这些基本上网上都有一些教程或者别人做的demo,我是按照这个方式去学习的.先做个demo,学会如何去使用它,接着去慢慢的了解它是如何的运行的,理解里面的一些基本的基础知识.我们不可以再像 ...

  3. canvas导出图片方法总结

    html代码 <canvas id="canvas" width="100" height="100" ></canvas ...

  4. 【原创】.NET Web API之filter ActionFilterAttribute 过滤器使用

    1.在filter类里面引用,与MVC里面的不同 using System.Web.Http.Controllers; using System.Web.Http.Filters; 2.filter类 ...

  5. 基于C#的MongoDB数据库开发应用(1)--MongoDB数据库的基础知识和使用

    在花了不少时间研究学习了MongoDB数据库的相关知识,以及利用C#对MongoDB数据库的封装.测试应用后,决定花一些时间来总结一下最近的研究心得,把这个数据库的应用单独作为一个系列来介绍,希望从各 ...

  6. Node.js系列之ubuntu环境搭建

    ctrl+alt+t打开终端(命令行) 一.准备Node.js所依赖的包(g++,curl,python等) sudo apt-get install g++ curl libssl-dev apac ...

  7. ISP接口隔离原则

    一.定义 不应该强迫客户程序依赖并未使用的方法 二.接口污染 接口污染,在C#.C++这样的静态类型语言中是很常见的.一个接口会被他不需要的方法污染.在接口中假如一个方法只是为了能给它的一个子类带来好 ...

  8. 【转】EL表达式 (详解)

    EL表达式      1.EL简介 1)语法结构        ${expression} 2)[]与.运算符      EL 提供.和[]两种运算符来存取数据.      当要存取的属性名称中包含一 ...

  9. FileIputeStream用于读写文件,并且用字节的方式表示出来

    package com.Java; import java.io.FileInputStream; import java.io.FileNotFoundException; import java. ...

  10. C# Winform反序列化复杂json字符串

    最近接的私单是一个CS项目,里面所有的操作都是通过调用API接口来进行的. 接口详细说明 协议:https  请求方式:post  https://xx.xxx.net/app/clients 提交j ...