UISearchBar的使用以及下拉列表框的实现
来源:互联网 发布:json配置文件怎么写 编辑:程序博客网 时间:2024/06/06 00:53
- @property (nonatomic,retain) UISearchBar* searchBar;
- _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
- _searchBar.placeholder = @"test"; //设置占位符
- _searchBar.delegate = self; //设置控件代理
- #pragma mark -
- #pragma mark UISearchBarDelegate
- //搜索框中的内容发生改变时 回调(即要搜索的内容改变)
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
- NSLog(@"changed");
- if (_searchBar.text.length == 0) {
- [self setSearchControllerHidden:YES]; //控制下拉列表的隐现
- }else{
- [self setSearchControllerHidden:NO];
- }
- }
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
- searchBar.showsCancelButton = YES;
- for(id cc in [searchBar subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:@"取消" forState:UIControlStateNormal];
}
}- NSLog(@"shuould begin");
- return YES;
- }
- - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
- searchBar.text = @"";
- NSLog(@"did begin");
- }
- - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
- NSLog(@"did end");
- searchBar.showsCancelButton = NO;
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
- NSLog(@"search clicked");
- }
- //点击搜索框上的 取消按钮时 调用
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
- NSLog(@"cancle clicked");
- _searchBar.text = @"";
- [_searchBar resignFirstResponder];
- [self setSearchControllerHidden:YES];
- }
- @interface SearchViewController : UITableViewController
- @end
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.tableView.layer.borderWidth = 1;
- self.tableView.layer.borderColor = [[UIColor blackColor] CGColor];
- }
- #pragma mark -
- #pragma mark Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- // 返回列表框的下拉列表的数量
- return 3;
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
- }
- // Configure the cell...
- NSUInteger row = [indexPath row];
- cell.textLabel.text = @"down list";
- return cell;
- }
- - (void) setSearchControllerHidden:(BOOL)hidden {
- NSInteger height = hidden ? 0: 180;
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.2];
- [_searchController.view setFrame:CGRectMake(30, 36, 200, height)];
- [UIView commitAnimations];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
- _searchBar.placeholder = @"test";
- _searchBar.delegate = self;
- _tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
- _tableview.dataSource = self;
- _tableview.tableHeaderView = _searchBar;
- _searchController = [[SearchViewController alloc] initWithStyle:UITableViewStylePlain];
- [_searchController.view setFrame:CGRectMake(30, 40, 200, 0)];
- [self.view addSubview:_tableview];
- [self.view addSubview:_searchController.view];
- }
0 0
- UISearchBar的使用以及下拉列表框的实现
- UISearchBar的使用以及下拉列表框的实现
- UISearchBar的使用以及下拉列表框的实现
- 使用PopupWindow实现的自定义下拉列表
- 使用PopupWindow实现Spinner的下拉列表
- 下拉列表的使用
- ios搜索框功能的实现/UISearchBar/UISearchController的使用
- 实现带复选框的下拉列表
- android 实现两个数字的乘法,页面之间的传值 以及菜单下拉列表的使用
- Android 的下拉列表框使用
- Android-下拉列表框Spinner的使用
- MAC 复选框,下拉列表的使用
- 下拉列表框Spinner的使用
- 二级下拉列表的实现
- 二级下拉列表的实现
- ALV 下拉列表的实现
- 下拉刷新列表的实现
- 级联下拉列表的实现
- 面试中的常用算法
- ACM-计算几何之改革春风吹满地——hdu2036
- Gitolite - g3 搭建 Git 服务器 详解
- 程序员的恶性循环
- Android基于百度定位SDK v4.1(LBS)实现定位功能
- UISearchBar的使用以及下拉列表框的实现
- SQL Server表分区注意事项
- 从(0,1)中平均随机出几次才能使得和超过1.(自然对数e次)
- 使用Gson对象将json格式的字符串与集合和对象互转
- 你手上有多少个螺,决定你的性格——real?
- 编程之美挑战赛 大神与三位小伙伴 题解
- 移动硬盘视频误删除如何恢复
- Android中Log图文详解
- 通过浏览器访问 memcache.php提示找不到该文件, 注意 httpd.conf 的 “documentroot”路径