On an iPhone App, I’ve got a custom keyboard which works like the standard keyboard; it appears if a custom textfield becomes first responder and hides if the field resigns first responder. I’m also posting the Generic UIKeyboardWillShowNotification, UIKeyboardDidShowNotification and their hiding counterparts, like follows:
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:5];
[userInfo setObject:[NSValue valueWithCGPoint:self.center]
forKey:UIKeyboardCenterBeginUserInfoKey];
[userInfo setObject:[NSValue valueWithCGPoint:shownCenter]
forKey:UIKeyboardCenterEndUserInfoKey];
[userInfo setObject:[NSValue valueWithCGRect:self.bounds]
forKey:UIKeyboardBoundsUserInfoKey];
[userInfo setObject:[NSNumber numberWithInt:UIViewAnimationCurveEaseOut]
forKey:UIKeyboardAnimationCurveUserInfoKey];
[userInfo setObject:[NSNumber numberWithDouble:thisAnimDuration]
forKey:UIKeyboardAnimationDurationUserInfoKey];
[[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillShowNotification
object:nil
userInfo:userInfo];
This code is working and I use it in UIViewController subclasses.
Now since iPhone OS 3.0, UITableViewController automatically resizes its tableView when the system keyboards show and hide. I’m only now compiling against 3.0 and I thought that the controller should also resize the table if my custom keyboard appears, since I’m posting the same notification. However it doesn’t. The table view controller is set as the delegate of the input fields.
Does anyone have an idea why this might be the case? Has anyone implemented something similar successfully?
I have standard input fields along the custom ones, so if the user changes the fields the standard keyboard hides and the custom one shows. It would be beneficial if the tableView didn’t resize to full height and I didn’t have to resize it back with a custom method.
Well there are a few possibilities that you poke around in. From your description, it seems that UITableView is not using the UIKeyboard Notifications.
But possibly, it is the UINavigationController that is responding to this notification (or UITabBarController).
You could override methods like setFrame: drawRect: and setNeedsDisplay in the tableview to see what is happening in the call stack. You may be able to figure out what is actually causing the tableview to redraw at the correct size.
But in all likelihood, just changing the size of the tableView yourself is the much easier solution. These suggestions are just for fun!