我正在通过代码包括搜索栏,并使用以下代码启用交互,搜索栏将显示,但当我单击字段时,编辑功能未启用:
let searchTableViewController = storyboard?.instantiateViewController(withIdentifier: "SearchBarTableVC") as? SearchBarTableVC
searchTableViewController?.handleMapSearchDelegate = self
searchTableViewController?.mapView = self.mapView
searchBarController = UISearchController(searchResultsController: searchTableVC)
searchBarController?.searchResultsUpdater = searchTableVC
let searchBar = searchBarController?.searchBar
searchBar?.sizeToFit()
searchBar?.placeholder = "Digite o local"
searchBar?.tintColor = UIColor.red
searchBar!.isUserInteractionEnabled = true
searchBar?.backgroundColor = UIColor(named: "ColorTransparent")
navigationItem.titleView = searchBarController?.searchBar
searchBarController?.hidesNavigationBarDuringPresentation = false
searchBarController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
发布于 2018-05-28 08:39:08
如果您使用的是iOS 11,首选的方法是简单地编写:
navigationItem.searchController = searchController
就这样。您不必定位搜索栏或将其放在任何视图中。
https://stackoverflow.com/questions/50557731
复制相似问题