0

I have a UITableView with UITextViews in each cell. I want to move the cell in which the user is editing the UITextView to the top of the table view.

This is easily achieved by:

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, self.view.frame.size.height - textViewHeight, 0);

However I have a very weird issue, which I can not find anything on, when searching for it. The cell is not moved up, until the keyboard has not finished animating on to the screen, no matter which method I set the contentInset in. It's as if the keyboard animation has some kind of priority.

After investigating, I found that setting the contentOffset at the same time, will actually move the cell up, even before the keyboard has finished animating.

Can somebody explain this behaviour to me, or explain whats going on?

Thanks!

Balázs Vincze
  • 3,550
  • 5
  • 29
  • 60

4 Answers4

0

When you UITextfield or UITextview will began editing method call at that time you can use UITableView Method

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, self.view.frame.size.height - textViewHeight, 0);
tableView.scrollToRowAtIndexPath(NSIndexPath, atScrollPosition: UITableViewScrollPosition, animated: Bool)

and you can scroll to top. i hope this will help you

Rohit Khandelwal
  • 1,778
  • 15
  • 23
jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
0

The Best way for these kind of scenerio's just install IQKeyboardManager Pods and it will automatically scroll tableview when you click on UITextView ,You don't need to write anything else.

Sumit Jangra
  • 651
  • 5
  • 16
0

you are using UITableView with ViewController. But to achieve what you want the best way is to use a UITableViewController.because, It autoamtically scroll up (scroll above to keyboard and focus on the editing textfield) when user enter any data.

caldera.sac
  • 4,918
  • 7
  • 37
  • 69
  • I need the functionality of a UIViewController, such as having a main UIView – Balázs Vincze Sep 28 '16 at 17:58
  • which functionalities you want ... take a look at this answer http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present?rq=1 – caldera.sac Sep 28 '16 at 18:01
-1

try observing keyboard notifications UIKeyboardWillShowNotification and UIKeyboardWillHideNotification, put your code into the selector method.

Lane
  • 119
  • 1
  • 5