Swift searchBar separates from the top of the View table after searchController.active during rotation

// Why does the tableView containing the searchResults array, after turning to the landscape and back to the portrait, push the top of the View table down, thereby separating the searchBar from the top of the tableView. This happens repeatedly after each turn to the landscape and back. This happens only after the start of the search. This does not happen during rotation if the searchController is not active.

class InitialViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {

@IBOutlet weak var tableView: UITableView!

let searchController = UISearchController(searchResultsController: nil)
let b = searchController.searchBar

b.sizeToFit() // crucial, trust me on this one
b.scopeButtonTitles = ["Drugs", "Tumor", "Target"]
tableView.tableHeaderView = searchController.searchBar
definesPresentationContext = true
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
+1
source share
1 answer

For some unknown reason, implementing the following function solves the rotation problem.

  override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) 
  {
    self.tableView.reloadData()
  }

func viewDidLoad, . , .

0

All Articles