I have a UISearchBar
. I want the the keyboard to go away as soon as user hits search...i did try resignFirstResponder
but that didn't work. any help would be appreciated
- (void)viewDidLoad {
[super viewDidLoad];
self.title = NSLocalizedString(@"Songs", @"Search for songs");
NSMutableArray *array = [[NSArray alloc]initWithObjects: @"Book_1", @"Book 2", @"Book _ 4", nil];
self.booksArray = array;
[array release];
search.delegate=self;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
thanks TC
It should work by implementing the respond methods at the delegate object:
Reference: http://www.iphonedevsdk.com/forum/iphone-sdk-development/7148-problem-uisearchbar-navigation-controller.html#post59467
Please make sure of following things.(I hope you are talking about search Button of keyboard.)
IBOutlet
of searchBar with its variablesearch
.- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
method is in sameviewcontroller
as searchBar is in.searchBarSearchButtonClicked
and verify that both instances are same if not then you aresearch
is getting reassigned somewhere in code.[searchBar resignFirstResponder];
NSLog(@"isFirstResponder : %d",[searchbar isFirstResponder]); andNSLog(@"Next Responder : %@",[searchBar nextResponder]);
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
method is being called when you tap search Button of keyboard? Make sure there are no keyboardresponder
(liketextField
,textView
or othersearchBar
) is added behind yoursearchBar
may be unintentionally. Please check it through xib also.Thanks,