0

I've read here that if I have UITextField in my table cells, the table scrolls automatically to the cell that contains them. This works perfectly. Making a UITableView scroll when text field is selected

Is there a way to get this to work with a UIViewController? I'm using a UIViewController because I have a lot of custom UI that needs to be laid out on top of the table view. Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
7ball
  • 2,183
  • 4
  • 26
  • 61

1 Answers1

0

I would recommend splitting your viewController into several using containerViews.

That way, you can use a UITableViewController for your tableView and use a regular UIViewController for all the custom UI.

Another way would be to set a scrollView's contentOffset manually when a textField is in focus.

It would look something like that.

@IBAction func textField(didBeginEditing sender: UITextField) {
    let point = CGPoint(x: 0, y: textField.frame.minY)
    scrollView.setContentOffset(point, animated: true) 
}
Senõr Ganso
  • 1,694
  • 16
  • 23