Xcode-除非这是根视图控制器,否则视图控制器的搜索栏不可见

时间:2020-08-05 20:05:58

标签: xcode

具有搜索功能的普通视图控制器:

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)
     }
   }

0 个答案:

没有答案