views:

537

answers:

1

I'm trying to implement a UITextView in a table cell at the bottom of a table view.

I've tried the suggestions here http://stackoverflow.com/questions/594181/uitableview-and-keyboard-scrolling-problem, and other solutions as well, but they're a bit different because I have to artificially add extra height to the current view in order to create space for the keyboard.

Here's what I added to the previous solution in order to port it to my app.

-(void) keyboardWillShow:(NSNotification *)note {
      CGRect frame = self.view.frame;
      frame.size.height += keyboardHeight;
      frame.origin.y -= keyboardHeight;
        self.view.frame = frame;
}

-(void) keyboardWillHide:(NSNotification *)note
{
        CGRect frame = self.view.frame;
        frame.size.height -= keyboardHeight;
    frame.origin.y += keyboardHeight;

}

Doing this will correctly add the height to the view and scroll to the cell, but after restoring the original view's height, scrolling beyond the current visible view becomes impossible, even though there is valid content outside of the boundaries (I see the text view before the scroll bar bounces back).
If I try to save the tableview's frame or bounds (not the view) in keyboardWillShow and restore them in keyboardWillHide, the scrolling will be restored, but the view will be cut in half.

Are there any remedies to this besides hard-coding the additional height to the bottom of the view?

A: 

I was able to solve my problem of the locked scrolling by removing the code that edits the view's origin. In addition, I implemented scrolling to the bottom cell by using the tableview's contentSize property in my calculations.

-(void) keyboardWillShow:(NSNotification *)note
{

  if(!isKeyboardShowing)
    {
 isKeyboardShowing = YES;
 CGRect keyboardBounds;
 [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &keyboardBounds];
 CGFloat keyboardHeight = keyboardBounds.size.height;

            CGRect frame = self.view.frame;
            frame.size.height += keyboardHeight;
            self.view.frame = frame;

 CGPoint scrollPoint = frame.origin;
 scrollPoint.y += _tableView.contentSize.height - keyboardHeight;
 [_tableView setContentOffset:scrollPoint animated:YES];
    }
}
oohaba