一些简单的UISearchBar使用

//添加搜索框

-(void)addsearchBar{       

 _search = [[UISearchBar alloc]init];  

  _search.placeholder = @"请输入搜索关键字"; 

   _search.delegate=self;    

self.navigationItem.titleView = _search;    }

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

//弹出框消失

[_search resignFirstResponder];

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

//弹出框消失

[_search resignFirstResponder];

}

/*键盘搜索按钮*/

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

[searchBar resignFirstResponder];

[self doSearch:searchBar];

}

/*搜索*/

- (void)doSearch:(UISearchBar *)searchBar{

TQ(@"提示", @"你点击了搜索", @"确定")

}

你可能感兴趣的:(一些简单的UISearchBar使用)