iOS 搜索框控件 最简单的dome
刚学习搜索框控件,写了个最简单的dome
#import <UIKit/UIKit.h>
.h
@interface ViewController : UIViewController<UISearchBarDelegate,UISearchDisplayDelegate,UITableViewDataSource,UITableViewDelegate> @property (nonatomic,strong) UISearchDisplayController *searchDisplayC;//搜索框控件控制器
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;//搜索条
@property (nonatomic,strong) NSArray *allArray;//全部数据数组
@property (nonatomic,strong) NSMutableArray *filterArray;//搜索出来的数据数组 @end
.m
#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize searchBar;
@synthesize searchDisplayC;
@synthesize filterArray;
@synthesize allArray; - (void)viewDidLoad
{
[super viewDidLoad]; allArray = [NSArray arrayWithObjects:@"济南",@"天津",@"潍坊",@"上海",@"北京",@"青岛",@"台湾",@"钓鱼岛", nil];
searchDisplayC = [[UISearchDisplayController alloc]initWithSearchBar:searchBar contentsController:self];
searchDisplayC.delegate = self;
searchDisplayC.searchResultsDelegate = self;
searchDisplayC.searchResultsDataSource = self;
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - tabledelegete - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return filterArray.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = [filterArray objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//选择后要做的事情
NSLog(@"已选择");
}
#pragma mark - searchdelegate - (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[filterArray removeAllObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",searchString];//用于过滤
filterArray = [NSMutableArray arrayWithArray:[allArray filteredArrayUsingPredicate:predicate]];
return YES;
} - (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
//当scope改变时调用
return YES;
}
@end
iOS 搜索框控件 最简单的dome的更多相关文章
- IOS中UITextView(多行文本框)控件的简单用法
1.创建并初始化 UITextView文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文.UITextField的用处多,UITextVie ...
- IOS自定义日历控件的简单实现(附思想及过程)
因为程序要求要插入一个日历控件,该空间的要求是从当天开始及以后的六个月内的日历,上网查资料基本上都说只要获取两个条件(当月第一天周几和本月一共有多少天)就可以实现一个简单的日历,剩下的靠自己的简单逻辑 ...
- iOS开发--UIKit控件之UISearchBar(搜索栏)
今天因为需求原因,需要用到搜索控件:之前一直没有用到过这个控件,所以去百度了一下,找到一篇可以说很齐全的资料,感谢这位作者. 然而,我并没有找到可以更改字体大小的属性或方法,希望有知道的告诉我一声,谢 ...
- Combo Box (组合框)控件的使用方法
Combo Box (组合框)控件很简单,可以节省空间.从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的.用户可以从一个预先定义的列表里选择一个选项,同时也可以直接在文本框里面输入文本 ...
- iOS:提示框(警告框)控件UIActionSheet的详解
提示框(警告框)控件2:UIActionSheet 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.它与导航栏类似,它继承自UIView. 风格类型: ...
- iOS:提示框(警告框)控件UIAlertView的详解
提示框(警告框)控件:UIAlertView 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能. 类型:typedef NS_ENUM(NSInte ...
- MFC编程入门之二十四(常用控件:列表框控件ListBox)
前面两节讲了比较常用的按钮控件,并通过按钮控件实例说明了具体用法.本文要讲的是列表框控件(ListBox)及其使用实例. 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选 ...
- 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件
转自:http://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI ...
- VS2010/MFC编程入门之二十四(常用控件:列表框控件ListBox)
前面两节讲了比较常用的按钮控件,并通过按钮控件实例说明了具体用法.本文要讲的是列表框控件(ListBox)及其使用实例. 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选 ...
随机推荐
- __autoload()方法
php中__autoload()方法详解 PHP在魔术函数__autoload()方法出现以前,如果你要在一个程序文件中实例化100个对象,那么你必须用include或者require包含进来100个 ...
- ASP.NET成员资格与角色管理配置内容
Web.config中进行配置 以便于连接数据库,使用微软提供的Membership类.·····等 <?xml version="1.0" encoding=" ...
- Do not wait until the conditions are perfect to begin. Beginning makes the conditions perfect(转)
名言金句总是不嫌多,美国<公司>杂志(Inc.)列出让你在 2015 年受用无穷的十大金句,每天选一则当作一天的心灵指导,不只学习前人的精神和智慧,也能转化成工作和生活的动力!Cheers ...
- [置顶] 提高生产力:Web开发基础平台WebCommon的设计和实现
Web开发中,存在着各种各样的重复性的工作.为了提高开发效率,不在当码农,我在思考和实践如何搭建一个Web开发的基础平台. Web开发基础平台的目标和功能 1.提供一套基础的开发环境,整合了常用的框架 ...
- hibernate解决oracle的id自增?
以前做SSH项目时,涉及到的数据库是mySQL,只需将bean的配置文件id设为native 就可以实现表id的自增. 现在用到了Oracle,当然知道这样是不行的啦,那么用序列自增? 我在网络上搜索 ...
- Eclipse中提高Android SDK Manager下载速度方法
在Windows-System32-drivers-ect目录下找到hosts文件 打开hosts文件(用记事本打开就可以),在文件以下填上一下内容: 203.208.46.146 www.googl ...
- unix ourhdr.h myerr.h
//在学UNIX环境高级编程时把下面两个头文件与源文件放在同一个文件下就可以正常编译了,我的是在ubuntu 12.04环境下,第一个程序编译和运行成功了,希望对大家有帮助(我已经根据网上的资料修改好 ...
- delphi中一切皆指针
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- UVA 529 Addition Chains(迭代搜索)
Addition Chains An addition chain for n is an integer sequence with the following four propertie ...
- 精讚部落::MySQL 的MEMORY engine
精讚部落::MySQL 的MEMORY engine MySQL 的MEMORY engine 無次要群組