具有搜索功能的普通视图控制器:
class PlacesViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Permits"
navigationItem.searchController = searchController
definesPresentationContext = true
}
}
当它是根视图控制器时,搜索栏将显示为OK。但是,如果我按如下所示通过按钮到达,则搜索栏不可见::
@IBAction func placesPressed(_ sender: Any) {
let placesVC = storyboard?.instantiateViewController(withIdentifier:”PlacesViewController”) as? PlacesViewController
if let placesVC = placesVC {
placesVC.modalPresentationStyle = .currentContext // tried variations
present(placesVC, animated: false, completion: nil)
}
}