【发布时间】:2015-12-22 23:15:40
【问题描述】:
我的故事板中的视图控制器上有一个 UISearchBar 和一个 UITableView。搜索栏位于 tableview 上方,因此它不会滚动。我的问题是 UISearchController 的初始化创建了自己的 SearchBar 实例,该实例与我手动添加并定位在情节提要上的实例不同。
如何将我的故事板 SearchBar 设置为我的 UISearchController 为我创建的?
class ITSearchController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
// So that the search results are displayed in the current controllers table view
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
// This didn't work
//var view = self.view.viewWithTag(777)
//view = searchController.searchBar
// This works but isn't what I want
//tableView.tableHeaderView = searchController.searchBar
// This works but places it in the nav section. Not what I want.
// self.navigationItem.titleView = searchController.searchBar
// This is what I want but doesn't work. Basically make the search bar on my storyboard equal to the one created.
searchBar = searchController.searchBar
}
}
【问题讨论】:
标签: ios swift uisearchbar uisearchcontroller