I have a UITableView with a few UITableViewCells. Each cell contains a UITextfield. Tapping the textFields causes the keyboard to display. Unfortunately the keyboard covers some of the cells that are lower on the iPhone’s screen.
What’s the easiest way to scroll the tableView up when the keyboard is displayed?
I’ve experimented with the contentOffset. This works for actually scrolling the tableView. However I’m having trouble determining which cell is “active” (has a textField that’s currently the firstResponder). My app supports both portrait and landscape orientation so the tableView sometimes needs to be scrolled when the device rotates.
A simple way to keep track of which textField is currently active is to set its
tagproperty to the indexPath’s row oncellForRowAtIndexPath:Another way is to use this line:
on
textFieldShouldBeginEditing:for when the textField becomes active, or on your rotation callbacks for when the device rotates, and then scroll the tableView usingscrollToRowAtIndexPath:atScrollPosition:animated: