0
votes

I've implemented UISearchController for ViewController with tableView on it and now I'm facing a problem of strange scrolling behavior of tableView. After scrolling tableView down and tapping status bar to scroll back to the top tableView isn't returning to its proper position (right under navigation bar). Looks like it stops its bounce back animation halfway. It goes back to the top if you touch the tableView after that though. Take a look at this gif to see it yourself.

The problem remains on a simulator and on a real device as well (iPhone7)

This is a code I setup searchController with:

class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {

@IBOutlet weak var tableView: UITableView!

var searchController = UISearchController(searchResultsController: nil)        

override func viewDidLoad() {
   searchController.searchResultsUpdater = self
   searchController.obscuresBackgroundDuringPresentation = false
   searchController.searchBar.placeholder = "Search..."
   navigationItem.searchController = searchController
   definesPresentationContext = true 
   }
...
}

What might cause such behavior and how to fix this?

1

1 Answers

0
votes

Maybe a couple things to try:

  • I remember setting the layout constraints to the Superview instead of the Safe Area help with my tableView's scrolling when the ViewController was embedded in a Navigation Controller.

  • Also adding this property to the ViewController might help if the first doesn't:

    extendedLayoutIncludesOpaqueBars = true