Question

Problem

I am having a rather big issue with the iOS7 keyboard appearance. I have a Searchbar on a UIViewController with TableView Delegation/Data Source setup (I am using the self.searchDisplayController delegates as well). I segue from this scene to a prototype tableview to show the results.

Here is the issue:

On first load I can see the keyboard being displayed when I tap into the text field of the UISearchBar. I can type and perform a search with the results being shown in the next scene.

I've added NSNotifications to view the keyboard properties in local methods keyboardWillShow and keyboardWasShown. I can see on the first scene appearance (after the view is completely loaded):

Keyboard Shown

I segue to the result tableview at this point and when I navigate back and touch the text field, my keyboard shows up either fully or partially off-screen:

Partial Keyboard

When I look at the keyboardWillShow notification at this point I can see that my keyboard values are incorrect:

Second round through

I've researched and tried many possibilities including:

Added the following to my main view controller:

-(BOOL)canResignFirstResponder
{
    return YES;
}
-(BOOL)canBecomeFirstResponder
{
    return YES;
}

Configured the following in my view did load

self.searchDisplayController.searchBar.spellCheckingType = UITextSpellCheckingTypeNo;
    self.searchDisplayController.searchBar.autocapitalizationType=  UITextAutocapitalizationTypeNone;
    self.searchDisplayController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    self.searchDisplayController.searchBar.keyboardType = UIKeyboardTypeDefault;

Put in standard stubs for:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

I've noticed that if I choose a Partial Curl as my segue mode, the keyboard remains accessible when I roll back to the main view controller (but then it was never fully off screen in that case). However if I move from the results tableview to a detail scene and then navigate back to the main view controller, the keyboard appears off-screen again.

Question

Is there a method I can use to intercept the misplaced keyboard so that it displays in the default location?

NB: Along these lines, I have created a NSDictionary property to hold the initial userInfo values with the correct keyboard placement. I am not sure how to reassign these values to get the keyboard to return to it's original placement.

BTW - This seems a bit of a hack to get the keyboard fixed due to a bug in IB, is there some other way that I can try to remedy the situation?

Thanks in advance for any feedback!

Was it helpful?

Solution

Solution

This was such an obscure issue that I'm sharing the solution to save the next person some effort. Like most programming issues, it turns out this one was self-inflicted. In my original iteration of this project I had turned off rotational support as I am learning auto-layout and I wanted to ease into the transition from Springs and Struts. Somehow between the start of the project and the code release I ended up with this bit of code in the Main Scenes' View Controller.

//BAD
- (NSUInteger) supportedInterfaceOrientations  
{
    return !UIInterfaceOrientationPortraitUpsideDown;
}

instead of returning a valid enumeration like...

//OK
- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top