Reputation: 612
I add the SearchBar view in NavigationBar.
[self.navigationController.view addSubview:self.searchBar];
When I am searching...
The search is complete...
If I want to cancel (remove) SearchBar, I must tap to Cancel button TWO time for remove SearchBar. (one time for focus SearchBar and one time for tap Cancel).
How can I just one tap to Cancel like (x) button (clear text button) in SearchBar? or How can SearchBar always focused? (on this way I can tap Cancel for close SearchBar only one tap)
Upvotes: 1
Views: 1025
Reputation: 1
When search bar has resigned from first responder, cancel button is disabled.
So you should enable the cancel button manually.
Try this:
[searchBar resignFirstResponder];
[(UIButton *)[searchBar valueForKey:@"_cancelButton"] setEnabled:YES];
Upvotes: 0
Reputation: 1236
Don't dismiss your keyboard after search
remove this line [searchBar resignFirstResponder]
It will work
Upvotes: 1
Reputation: 2148
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame = self.archiveListTblView.frame;
}
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
controller.active=NO;
[self.view addSubview:controller.searchBar];
}
Upvotes: 0
Reputation:
Implement the search bar delegate method as :
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
self.navigationController.navigationBarHidden = NO;
[mySearchBar setAlpha:0.0];
}
Hope you have got the idea by doing this. Also you can add it directly to navigation controller, itself, if you want & then play with Showing/ hiding the searchBar
alone.
Upvotes: 0