搜索栏的使用(UISearchBar)(跳转到下一个页面,搜索栏消失)
2015-09-28 19:08 真实16 阅读(1039) 评论(0) 编辑 收藏 举报导航栏上 添加按钮和触发事件(一句代码添加导航栏的按钮和方法)
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"删除" style:UIBarButtonItemStylePlain target:self action:@selector(selectRightAction:)];
1、初始化搜索栏
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectmake(100,100,100,100)];
// 设置搜索栏的圆角
*** searchBar.layer.cornerRadius = 10;
// 挂上代理(要用到代理的里面的方法,让搜索栏回收键盘)
searchBar.delegate = self;
// 设置搜索栏的tag值(目的就是让搜索栏的消失和出现)
2、让搜索栏添加到导航栏上
[self.navigationController.navigationBar addSubview: searchBar]
————搜索栏(点击回收键盘)
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
———让搜索栏出现
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController,navigationBar viewWithTag:100].hidden = NO;
}
—让搜索栏消失(跳转到下一个页面)
- (void)viewDidDisappear:(BOOL)animated
{
[self . navigationController . navigationBar viewWithTag: 100].hidden = YES;
}