0

I have many textfields and one textview at the bottom of the form. All these are embedded in a tableview. I am able to move the tableview up on click of any textfield.

Question: How do I achieve the same for a textview. Any help would be appreciated.

The code that I used to move the tableview up on click of a textfield is this -

func textFieldShouldBeginEditing(textField: UITextField) -> Bool {

let txtFieldPosition = textField.convertPoint(textField.bounds.origin, toView: profileTableView)
        let indexPath = profileTableView.indexPathForRowAtPoint(txtFieldPosition)
        if indexPath != nil {
            profileTableView.scrollToRowAtIndexPath(indexPath!, atScrollPosition: .Top, animated: true)
        }
return true
 }
Amanpreet
  • 1,301
  • 3
  • 12
  • 29
Kavitha Pai
  • 51
  • 3
  • 11

1 Answers1

0

Make NotificationCenter for keyboard appear and disappear.

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillAppear), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillDisappear), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

Add two functions.

func keyboardWillAppear(notification: NSNotification){
    //manage UI
}

func keyboardWillDisappear(notification: NSNotification){
    //manage UI
}
Jay Patel
  • 2,642
  • 2
  • 18
  • 40