Question

I have make like text field search.

In which i have first create text field and also add new UISearchViewController

Now i have set

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
        [textField resignFirstResponder];
    self.searchDisplayController.searchBar.hidden = FALSE;
    [self.searchDisplayController.searchBar becomeFirstResponder];
    [self.searchDisplayController setActive:YES animated:NO];
}

but i have seen only search display controller and black background with out keyboard

when i directly pressed in search bar it's shows keyboard

what should i do for show keyboard in UISearchBarController from above method

EDIT

Please download my code from here http://sourceforge.net/projects/locationdemo/files/LocationDemo.zip/download

Was it helpful?

Solution 2

Finally I have my answer which want to share with every one

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
        [textField resignFirstResponder];
        NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(keyboardWasShown:) userInfo:nil repeats:NO];
}

- (void)keyboardWasShown:(NSNotification *)notification
{
    [self.searchDisplayController.searchBar becomeFirstResponder];
    self.searchDisplayController.searchBar.hidden = FALSE;
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    CGRect aRect = self.view.frame;
    aRect.size.height -= keyboardSize.height;
}

OTHER TIPS

This line is going to create problems:

[textField resignFirstResponder];

WHy is it there. If you want to show the keyboard. You should not be calling this at this point. That will Dismiss or Hide the keyboard?

Well where do you call [textField becomeFirstResponder] ?

You can also use this UISearchBar, rather than try to write your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top