Is there any way to select all text in UISearchBar? I tried [searchBar selectALL:], but it throw the signal (unrecognized selector).
I want to allow user to alter previous search text. At the some time, when user just starts typing new request, the old one should be dismissed. The standard way how to achieve it - select all text at the moment when text begin editing.
This can be accomplished using the standard UIResponder semantics. No need to dig down into the private view hierarchy of UISearchBar.
[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]
You can call this from anywhere, and the selectAll:
selector will run the responder chain to see if any objects respond to it. Assuming your search bar is currently the first responder (if the user is typing in it), it will respond and the result will be all text selected. If not you can make it the first responder by calling becomeFirstResponder
on the search bar.
[_mySearchBar becomeFirstResponder]
[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With