1

//为什么包含searchResults数组的tableView在转成横向再转回纵向后,会将tableView的顶部向下推,从而将searchBar与tableView的顶部分开。这在每次旋转到横向和返回后重复发生。这仅在进行搜索后发生。如果 searchController 未激活,则不会在旋转时发生。

类 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
4

1 回答 1

0

For some unknown reason implementing the following function solved the rotation issue.

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

Paste the above func after viewDidLoad function and my problem disappeared. Don't know why. Glenn Tisman

于 2014-11-26T12:37:48.710 回答