iOS UISearchDisplayController学习笔记
UISearchDisplayController和UISearchBar一起使用用来管理UISearchBar和搜索结果的展示。UISearchDisplayController提供了显示搜索结果的tableview来覆盖原控制器的视图;
使用UISearchDisplayController须要:
- 提供搜索结果table的数据的来源-searchResultsDataSource
- 搜索结果table的代理 SearchResultsDelegate
- UISearchDisplayController控制器的代理delegate ,对应搜索事件的開始结束和显示隐藏界面;(这个代理知道搜索字符串的改变和搜索范围,所以结果table可以(自己主动)又一次导入)
- searchBar的代理(关于UISearchBar代理上篇文章已经说明)
一般是在在uitableview中初始化UISearchDisplayController来展示一个列表。
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
在tabelview代理方法中须要推断是哪一个table(UITableViewController中有self.tableView UISearchDisplayController中有.searchResultsTableView)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.tableView) {
return ...;
}
// If necessary (if self is the data source for other table views),
// check whether tableView is searchController.searchResultsTableView.
return ...;
}
一个UIViewController和一个UISearchBar仅仅有一个UISearchDisplayController。
你可以在ios7 之后,在navigationbar中使用SearchDisplayController,通过配置UISearchDisplayController中得displaysSearchBarInNavigationBar和
navigationItem属性;
相关的属性和方法
@property(nonatomic, getter=isActive) BOOL active
展现(是否隐藏)状态。默认值是NO。直接设置没有动画,用setActive:animated: 设置会有动画
@property(nonatomic,
assign) id<UISearchDisplayDelegate>
delegate
代理
@property(nonatomic,
assign) BOOL displaysSearchBarInNavigationBar
指定navigationbar中包括一个searchBar
@property(nonatomic,
readonly) UINavigationItem *navigationItem
仅仅读属性 代表在navigation controller的navigationbar中的searchdisplaycontroller;
@property(nonatomic, readonly) UISearchBar *searchBar
UISearchDisplayController中的UISearchBar;
@property(nonatomic,
readonly) UIViewController *searchContentsController
这个属性管理着搜索出的内容
@property(nonatomic,
assign) id<UITableViewDataSource>
searchResultsDataSource
展示搜索结果的数据来源
@property(nonatomic,
assign) id<UITableViewDelegate>
searchResultsDelegate
搜索结果展示的table的代理
@property(nonatomic,
readonly) UITableView *searchResultsTableView
搜索结果展示的table
@property(nonatomic,
copy) NSString *searchResultsTitle
搜索结果视图的标题
-
(id)initWithSearchBar:(UISearchBar *)searchBar contentsController:(UIViewController *)viewController
初始化控制器
指定关联的search 和view controller
- (void)setActive:(BOOL)visible animated:(BOOL)animated
展现或者隐藏搜索视图
内容来自苹果文档
iOS UISearchDisplayController学习笔记的更多相关文章
- iOS音频学习笔记二:iOS SDK中与音频有关的相关框架
上层: Media Player Framework: 包含MPMoviePlayerController.MPMoviePlayerViewController.MPMusicPla ...
- iOS音频学习笔记一:常见音频封装格式及编码格式
(1) pcm格式 pcm是经过话筒录音后直接得到的未经压缩的数据流 数据大小=采样频率*采样位数*声道*秒数/8 采样频率一般是22k或者44k,位数一般是8位或者16位,声道一 ...
- iOS开发学习笔记:基础篇
iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...
- iOS开发学习笔记
1 常用的第三方工具 1.1 iPhone Simulator 测试程序需要模拟器iPhone Simulator 1.2 设计界面需要Interface Builder,Interface Buil ...
- iOS - CAEmitterLayer 学习笔记一
其他参考博客: http://my.oschina.net/u/2340880/blog/485095 http://www.cnblogs.com/YouXianMing/p/3785876.htm ...
- ios开发学习笔记(这里一定有你想要的东西,全部免费)
1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [ ...
- iOS开发应用学习笔记
一.iOS应用设计 1. 参考资料: 解读iPhone平台的一些优秀设计思路 iPhone App的特点及基本设计方法 Mobile UI design and Developer 2. 用户对iPh ...
- ios 框架学习笔记
ios主要的系统层次: 一.Cocoa Touch 层:创建应用程序主要使用的框架. 1.关键技术: AirDrop:实现应用间通信. Text Kit:处理文本和排版. UIKit Dynamics ...
- ios 存储学习笔记
一.主要路径: Library/Caches/此文件用于存储那些需要及可延迟或重创建的临时数据.且这些内容不会被IOS 系统备份,特别地,当设备磁盘空间不足且应用不在运行状态时,IOS 系统可能会移除 ...
随机推荐
- Linux内核IP层的报文处理流程(一)
本文主要讲解了Linux内核IP层的整体架构和对从网卡接受的报文处理流程,使用的内核的版本是2.6.32.27 为了方便理解,本文采用整体流程图加伪代码的方式对Linxu内核中IP整体实现架构和对网卡 ...
- Mercurial简介
前言 目前所在的公司的版本控制使用的是Mercurial,它也有一个对应的客户端小乌龟,但是Mercurial跟我们之前使用的SVN有着本质的区别,对于其区别会在下一篇中介绍到,这次主要是带领 ...
- IOS开发-通知与消息机制
在多数移动应用中不论什么时候都仅仅能有一个应用程序处于活跃状态.假设其它应用此刻发生了一些用户感兴趣的那么通过通知机制就能够告诉用户此时发生的事情. iOS中通知机制又叫消息机制,其包含两类:一类是本 ...
- JavaScript语言基础知识10
JavaScript中间if声明: <span style="font-size:18px;"><HTML> <HEAD> <TITLE& ...
- Blink: Chromium的新渲染引擎
编自http://www.chromium.org/blink 关于blink Google Chrome/Chromium 从创始至今一直使用 WebKit(WebCore) 作为 HTML/CSS ...
- Flex强制类型转换错误
1.错误描写叙述 TypeError: Error #1034: 强制转换类型失败:无法将 HoleDetailInnerClass0@c2cccf1 转换为 mx.controls.listClas ...
- 比量iOS6/iOS7, 3.5inch/4.0inch
Retina (3.5/4 inch Screen) or Non-Retina 比量 if ([[UIScreen mainScreen] respondsToSelector:@selector( ...
- 【POJ1741】Tree 树分而治之 模板略?
做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog. ...
- 使用2DToolkit报错“ OverflowException: Value is too large”
今天使用2DToolkit做图集和动画时报错“ OverflowException: Value is too large”,大侠们说是字符串转整型时超过了Int的大小范围,所以报错.后来我一位同事高 ...
- Socket通信原理
对TCP/IP.UDP.Socket编程这些词你不会很陌生吧?随着网络技术的发展,这些词充斥着我们的耳朵.那么我想问: 1. 什么是TCP/IP.UDP?2. Sock ...