0

I'm using a UITableView in a universal app. It has a custom cell with UITextFields and the custom cell has a height of 110. The loop is because I'm using outlet collections - there should only be one instance in iPad and one in iPhone. The iPhone does not rotate. I'm using nibs rather than storyboards. I'm using autorotate and autolayout. My autolayout constraints for the UITableView are:

  • Top - 1 from toolbar above - pri 1000
  • Left - 83 from button - pri 1000
  • Right - 20 from Super - pri 1000
  • Bottom - 20 from Super - pri 1000
  • Height <= 845 - pri 750 or 1000 (also tried without a height
    constraint / no impact)

The nib was designed in portrait mode. When I run the iPad app and the keyboard extends in portrait, the UITableView scrollToRowAtIndexPath correctly places the row just above the keyboard. When I extend the keyboard in landscape mode, the cells scroll up and way out of view - I have to manually scroll them back down to enter text.

Here is my code to extend and hide:

- (void)portKeyboardWillShow:(NSNotification *)aNotification

{ CGRect keyboardBounds = [[[aNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];

for (int i=0; i<[self.tvPortsList count]; i++) {
    //when keyboard is up, that time just bring your text filed above the keyboard
    [[self.tvPortsList objectAtIndex: i] setContentInset: UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0)];

    [[self.tvPortsList objectAtIndex: i] setScrollIndicatorInsets: UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0)];

    [[self.tvPortsList objectAtIndex: i] scrollToRowAtIndexPath: self.portIndexPath
                                            atScrollPosition:UITableViewScrollPositionBottom
                                                    animated:YES];
}
[UIView commitAnimations];

}

Mickey
  • 11
  • 1
  • Update: In portrait mode, CGRect keyboardBounds = [[[aNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; returns keyboardBounds CGRect origin=(x=0, y=1024) size=(width=768, height=264) but in landscape mode, it returns keyboardBounds CGRect origin=(x=-352, y=0) size=(width=352, height=1024) . It appears that height and width are backwards. Is this expected behavior? – Mickey Jan 09 '14 at 20:15
  • Found it. Was searching for the wrong thing apparently. http://stackoverflow.com/questions/3332364/uikeyboardframebeginuserinfokey-uikeyboardframeenduserinfokey – Mickey Jan 09 '14 at 22:08

0 Answers0