Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a tableviewcell scroll up on displaying keyboard

I have a UITableViewCell with UITextField. In the edit mode, when the keyboard comes up, the row I am trying to edit gets overlapped by the keyboard. Ideally the row should scroll up so that I can edit the cell.

I have searched stackoverflow throughly and found several different solutions. Most of them has to do with calculations to move or scroll the view up. Now there is a sample code from apple called TaggedLocations. They have the exact same behavior. And there is no code doing any complex calculations to move the view up.

I also thoroughly checked the IB interface and could not find any fancy thing going on either. If you download and run the code, it beautifully pushes up the row to a perfect position for the edit.

Does anybody know what trick is there in the TaggedLocations project which does this so elegantly? Location of the project: http://developer.apple.com/library/ios/#samplecode/TaggedLocations/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40008914

For the complex calculations I was referring, look at the following thread for example:

How to make a UITextField move up when keyboard is present?

thanks

like image 364
mbh Avatar asked Nov 04 '22 21:11

mbh


1 Answers

This line in RootViewController.m is what causes the scroll:

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

Put that in your cellForRowAtIndexPath: method and it should work.

like image 198
Scott Berrevoets Avatar answered Nov 09 '22 12:11

Scott Berrevoets