I have a UISearchBar on my main ViewController. Below this search bar is a map so I figure that I need a second ViewController specifically for searching.
My current approach is to add a uitapgesturerecognizer to the search bar on my main ViewController so that when the user clicks on the search bar, they are seamlessly redirected to the second view.
My code:
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(segueToSearch:)];
[searchBar addGestureRecognizer:singleFingerTap];
and
- (IBAction)segueToSearch:(id)sender {
NSLog(@"about to segue");
}
This works when I do singleFingerTap.numberOfTapsRequired = 2
but obviously I want it to work with one tap.
Is my approach valid and if so what is wrong or is there another way to do this?
UISearchBar
has a UISearchbarDelegate
protocol which you can use to get notified when the users attempts to edit the inputfield.
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
// here you open the viewController
return NO;
}
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