// 搜索功能实现的主要代码
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 30)];
self.searchBar.barTintColor = HomeColor;
// 搜索栏半透明
self.searchBar.translucent = YES;
// 代理
self.searchBar.delegate = self;
_searchBar.placeholder = @"自定义分类搜索";
_searchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
_searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
[self addSubview:self.searchBar];
//点击搜索
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
ListViewController *listVC = [[ListViewController alloc] init];
listVC.keyWord = searchBar.text;
// 收回取消按钮
self.searchBar.showsCancelButton = NO;
self.searchBar.text = @"";
// 结束编辑 (回收键盘)
[self endEditing:YES];
[self.target pushViewController:listVC animated:YES];
[listVC release];
}
//搜索内容改变
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
}