Using a UITextView in a UITableViewCell with a UIKeyboard

Posted by Luther Baker on Stack Overflow See other posts from Stack Overflow or by Luther Baker
Published on 2010-04-24T09:46:32Z Indexed on 2010/04/24 9:53 UTC
Read the original article Hit count: 749

I have a simple UITableView that has two cells. Cell 0:0 consists of a UITextField we'll call the title and Cell 0:1 consists of a UITextView we'll simply call a note. Cell 0:0 (the text field) is a standard size, one row cell. I'm therefore trying to fill the rest of the screen up with Cell 0:1 so I return a larger height for it. This all displays just fine and I'm using most of the iPhone real estate pretty efficiently at this point.

Now, when a user wants to edit one of these cells, he need only click in the appropriate textfield or textview. If a user clicks in the textfield of Cell 0:0, all is well and the keyboard slides up from the bottom. My problem occurs when a user clicks into the the textview (Cell 0:1). No matter what I try, the UITableView wants to slide the entire table view up and that generally put the UITextView in Cell 0:1 halfway out of sight.

What I want to do is two fold, I'm registered for when the keyboard will appear and in that method, I'd like to shrink the UITextView in Cell 0:1 as well as shrink the UITableViewCell itself so that the keyboard doesn't have to be smart and think it has to slide the UITableViewCell into view. Unfortunately, no matter what I try, the UITableView slides up. I just want the UITableView to stand still and I want the cell to animate up/shorter with the keyboard.

It appears that, by the time the keyboard is actually animating into the screen - it is to late to adjust the cell size. The UIKit has already made up it's mind that it is going to scroll the UITableView.

© Stack Overflow or respective owner

Related posts about uitableviewcell

Related posts about uikeyboard