TableView表头加SearchBar
- (void)viewDidLoad {
[super viewDidLoad];
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
table.delegate = self;
table.dataSource = self;
[self.view addSubview:table];
[table release];
search = [[UISearchBar alloc] initWithFrame: CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40)];
search.placeholder=@"Enter Name";
search.delegate = self;
search.showsCancelButton = YES;
table.tableHeaderView = search;
search.keyboardType = UIKeyboardTypeDefault;
}
//search Button clicked....
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar // called when keyboard search button pressed
{
NSLog( @"111");
[searchBar resignFirstResponder];
}
//cancel button clicked...
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar // called when cancel button pressed
{
NSLog( @"222");
[searchBar resignFirstResponder];
}