我试图实现与日历应用程序类似的功能,到目前为止,我有下面的代码,当我点击leftBarButton时,只显示一个小的空白空间?为什么没有searchBar呢? 我想要的是当你点击一个带有searchBar
的新导航栏时当我点击searchButton时的插图:
代码:
override func viewDidLoad() {
super.viewDidLoad()
//searchBar
theSearchBar = UISearchBar(frame: CGRectZero)
theSearchBar?.delegate = self
theSearchBar?.showsCancelButton = true
theSearchBar?.placeholder = "Søg efter produkter"
searchController = UISearchDisplayController(searchBar: theSearchBar!, contentsController: self)
searchController?.delegate = self
searchController?.searchResultsDelegate = self
searchController?.searchResultsDataSource = self
}
@IBAction func showSearchBar(sender: UIBarButtonItem) {
theSearchBar?.becomeFirstResponder()
searchController?.setActive(true, animated: true)
}