Tuesday, 6 August 2013

UISearchBar becomeFirstResponder not showing keyboard

UISearchBar becomeFirstResponder not showing keyboard

Something peculiar is happening in my code with my UISearchBar and I can
not figure out what is happening. In my application I have a view
controller set up as follows
View Controller A ---> View Controller B
On View Controller A, I have a toolbar that contains a "page curl" button.
Once this button is tapped, I perform a modal segue with a page curl
transition style and I display View Controller B (this gives the user the
effect that View Controller B is beneath View Controller A when in reality
they are two distinctly seperate View Controllers). On View Controller B,
I have a button called "Find Near Address." When a user taps "Find Near
Address" I am looking for two actions to occur in seamless succession:
1) First, I would like to perform an unwind segue (undo the page curl
transition and curl View Controller A back onto View Controller B)
2) Secondly, Once View Controller B has disappeared and View Controller A
is the main view again, I would like for a UISearchBar on View Controller
A to become the first responder, meaning a flashing cursor should appear
in the search bar and a keyboard should pop up.
So far, I have been able to perform the unwind segue successfully but when
trying to set my UISearchBar on View Controller A as first responder, the
keyboard is not popping up! I am completely lost and I do not know why
this is happening.
The approach I have taken is simple. The unwind segue on view Controller B
returns and steps into a function call on View Controller A called
"(IBAction)returnToMainView:(UIStoryboardSegue *)segue." Now from within
this function, I call "[self FindNearAddress]" and below is my
FindNearAddress function
(void)FindNearAddress { [self.theSearchBar becomeFirstResponder]; }
I have also implemented the following UISearchBarDelegate methods
(void)searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar {
[self.theSearchBar setShowsCancelButton:YES animated:YES];
self.theSearchBar.text = @""; }
(void)searchBarCancelButtonClicked:(UISearchBar *)theSearchBar {
self.theSearchBar.text=@"Please enter a custom address..";
[self.theSearchBar setShowsCancelButton:NO animated:YES];
[self.theSearchBar resignFirstResponder]; }
Can anyone please help me/point out what I am doing wrong? I would like to
point out that I added a test button on View Controller A that calls my
"FindNearAddress" function and this succeeded in making my UISearchBar
first responder and bringing up the keyboard. The keyboard only fails to
pop up when I am returning (unwinding) from View Controller B, the first
responder gets set but the keyboard does not pop up for some strange
reason.

No comments:

Post a Comment