Reputation: 1003
I'm trying to implement a searchbar in my project.
I have already created the SearchBar outlet, have set the delegate, but when I press any keyboard button, the value from this button does not appear in UISearchBar
Can anybody tell me why?
- (void)searchBarSearchButtonClicked:(UISearchBar *)aSearchBar {
// When the search button is tapped, add the search term to recents and conduct the search.
NSString *searchString = [aSearchBar text];
NSLog(searchString);
}
Upvotes: 1
Views: 344
Reputation: 1003
I have missed the code below in appDelegate , applicationDidFinishLauching
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
Now the SearchBar is working fine!
Upvotes: 0
Reputation: 21966
Maybe you forgot to implement this method:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
return YES;
}
By returning YES you "say" that you accept editing.
EDIT
You don't even need to implement this method, by default a UISearchBar accepts editing.
No extra method is need to be implemented.
To be sure I've just did the following:
Works perfectly.Make sure that you have done all in the right way.
Upvotes: 1
Reputation: 1003
I have forgot this method
-(BOOL) searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
return YES;
}
Upvotes: 0