In my app, I have a navigation bar, a tab bar, a search bar and I always show the keypad.
However, with the different screen height with the iphone 5, I need to adjust the height of my table.
I can’t anchor the table to the top of the keypad as this is shown a run time.
So I’m trying to do this dynamically, it looks like I’m missing the search bar, just too short, hmmm.
Perhaps there’s an easier more obvious way?
EDIT: My code so far.
-(void)keyboardWillShow:(NSNotification*)aNotification {
int th = self.view.frame.size.height;
NSDictionary *info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]
CGRectValue].size;
int tableTop;
int tableHeight;
tableTop = table.frame.origin.y;
tableHeight = (th - tableTop) - kbSize.height;
[table setFrame:[General setTableBoundsByHeight:tableHeight:table]];
}
+ (CGRect)setTableBoundsByHeight:(int)lHeight:(UITableView*)tbl {
CGRect tableFrame = tbl.frame;
return CGRectMake(tableFrame.origin.x,
tableFrame.origin.y,
tableFrame.size.width,
lHeight);
}
I am guessing your “tableView” is part of your “self.view”. If it is, it is in a different coordinate system.
The keyboard is added to the window, and tableView is on your view hierarchy. You will need to use the functions described here under the heading: Converting Between View Coordinate Systems
EDIT: If you read the documentation on UIKeyboardFrameEndUserInfoKey, you will see it mentions the rectangle is in screen coordinates, while your UITableView is almost certainly in some other views coordinate system. In the same documentation they mentioned the function to convert between the two.