UISearchBar和UISearchDisplayController
来源:互联网 发布:前锦网络 编辑:程序博客网 时间:2024/05/16 18:16
一:添加searchBar的两种方式:
////////////添加搜索栏方式一:直接画一个,画不好的话会覆盖别的东西/////
/////////////添加搜索栏方式二:添加置tableView上////////////////
二、searchBar的结构了解:
iPhone开发之UISearchBar学习是本文要学习的内容,主要介绍了UISearchBar的使用,不多说,我们先来看详细内容。关于UISearchBar的一些问题。
1、修改UISearchBar的背景颜色
UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法是直接将 UISearchBarBackGround移去
第二种解决的方法:
[[searchBar.subviews objectAtIndex:0]removeFromSuperview];
换cancel的样式:
for(id cc in [searchBar subviews])
三、serarBar的属性及代理:
UIBarStyle barStyle
控件的样式
id delegate
设置控件的委托
NSString *text
控件上面的显示的文字
NSString *prompt
显示在顶部的单行文字,通常作为一个提示行
NSString *placeholder
半透明的提示文字,输入搜索内容消失
BOOL showsBookmarkButton
是否在控件的右端显示一个书的按钮(没有文字的时候)
BOOL showsCancelButton
是否显示cancel按钮
BOOL showsSearchResultsButton
BOOL searchResultsButtonSelec
UIColor *tintColor
bar的颜色(具有渐变效果)
BOOL translucent
指定控件是否会有透视效果
UITextAutocapitalization
autocapitalizationType
UITextAutocorrectionType
autocorrectionType
UIKeyboardType
keyboardType
键盘的样式
NSArray *scopeButtonTitles
搜索栏下部的选择栏,数组里面的内容是按钮的标题
NSInteger selectedScopeButtonIndex
BOOL showsScopeBar
控制搜索栏下部的选择栏是否显示出来代理列表:
编辑代理
–
searchBar:textDidChange: –
searchBar:shouldChangeTextInRange:replacementText: –
searchBarShouldBeginEdit ing: –
searchBarTextDidBeginEdi ting: –
searchBarShouldEndEditin g: –
searchBarTextDidEndEditi ng:
点击按钮
–
searchBarBookmarkButtonC licked: –
searchBarCancelButtonCli cked: –
searchBarSearchButtonCli cked: –
searchBarResultsListButt onClicked:
范围代理
–
searchBar:selectedScopeButtonIndex DidChange: - 利用UISearchBar的委托事件
textDidChange, 当在搜索框中输入完成后,如果输入的文本长度>0,可以调用自己的搜索方法,得到搜索结果,然后再reloadData,刷新一下。如果输入文本长 度<0,则需要恢复到原始数据。这个方法可以在边输入搜索文本边显示结果。 如果需要按“search”按钮再搜索,则将上述操作放在searchBarSearchButtonCli cked中。 - searchBar的范围控件showsScopeBar,官方学名叫Scope Buttons。
首先就要设置这个属性:
self.searchBar.showsScopeBar= YES;
然后要给他添加按钮。比如说,这样:self.searchBar.scopeButtonTitles= [NSArray arrayWithObjects:@"BOY",@"GIRL",@"ALL",nil];
还有一个很重要的事情就是我们要实现这个代理UISearchBarDelegate里的这个方法searchBar:selectedScopeButtonIndexDidChange:。告诉表格,你选择的范围是啥。
还有要是设置默认选择哪个按钮的话,要设置这个属性,像这样就是默认选中第1个啦。
self.searchBar.selectedScopeButtonIndex= 0;
四、UISearchDisplayControlle
利用UISearchDisplayControlle
属性:
active————是搜索界面可视化,默认为no,可用setActive方法设置.
delegate————委托
searchBar————在searchdisplaycontroller初始化后,searchbar是不可修改的,是readonly属性的.
searchContentController————管理搜索内容的试图控制器,一般是一个UITableViewController的实例,意思是针对一个UITableView的内容进行搜索
searchResultsDataSource————搜索结果的数据源
searchResultsDelegate————搜索结果的委托
searchResultsTableView————搜索结果要展示在哪个tableview中(read-only);
searchResultsTitle————搜索结果视图的title
初始化一个searchDisplayController:
在正常初始化完一个searchBar后再加上如下代码:
使用UISearchDisplayDelegate的委托方法进行搜索操作:
1.搜索状态改变:
–
searchDisplayControllerW illBeginSearch: –
searchDisplayControllerD idBeginSearch: –
searchDisplayControllerW illEndSearch: –
searchDisplayControllerD idEndSearch:
2.装载和卸载tableview:
–
searchDisplayController:didLoadSearchResultsTabl eView: –
searchDisplayController:willUnloadSearchResultsT ableView:
3.显示和隐藏tableview:
–
searchDisplayController:willShowSearchResultsTab leView: –
searchDisplayController:didShowSearchResultsTabl eView: –
searchDisplayController:willHideSearchResultsTab leView: –
searchDisplayController:didHideSearchResultsTabl eView:
4.搜索条件改变时响应:
–
searchDisplayController:shouldReloadTableForSear chString: –
searchDisplayController:shouldReloadTableForSear chScope:
searchDisplayController 自身有一个searchResultsTableView,所以在执行操作的时候首先要判断是否是搜索结果的tableView,如果是显示的就是搜索结 果的数据,如果不是,是TableView自身的view,则需要显示原始数据。
这样就不需要每次都realoadData了。
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchDisplayController 和 UISearchBar
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar 和 UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchDisplayController和UISearchBar
- 自定义UISearchBar和UISearchDisplayController
- iOS UISearchBar和UISearchDisplayController
- Oracle停止正在进行的job
- Type Syntax error, insert ")" to complete Expression
- 算法导论9 Random_Select
- ACM-对称博弈之Coin Game——hdu3951
- cocos2d-x安装配置步骤
- UISearchBar和UISearchDisplayController
- [LeetCode] Spiral Matrix II
- C# 中 PadLeft和PadRight 的用法
- 黑马程序员 第27天 多线程安全问题 线程停止
- 一个简单的链表类模板
- uva10387
- Android 事件分发 OnClickListener 和 OnTouchListener 的事件处理原理简单描述
- java获取两个字符串中最大相同子串。第一个动作:将短的那个串进行长度一次递减的子串打印
- 第九周项目一