I have UITableViewController where i was adding UISearchController searchbar as an headerView and I have changed this to navigationItem.searchcontroller for iOS 11 in iOS 11 searchbar won't appear at all even navigationItem was present.
如果不使用此搜索栏,则用户界面将进行折腾。请告诉我这里我做错了什么。
let searchController = UISearchController(searchResultsController: vc)
searchController.searchBar.scopeButtonTitles = ["All", "images", "videos", "others"]
searchController.dimsBackgroundDuringPresentation = false
// Don't remove these two lines then search bar alignment issue will raise
self.extendedLayoutIncludesOpaqueBars = true
self.searchController.searchBar.isHidden = false
definesPresentationContext = false
if #available(iOS 11.0, *) {
self.navigationItem.searchController = searchController // not working for me.
searchController?.hidesNavigationBarDuringPresentation = false
navigationItem.hidesSearchBarWhenScrolling = false
} else {
searchController?.hidesNavigationBarDuringPresentation = true
searchController?.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
}
问题清单
答案 0 :(得分:0)
我不确定那里出了什么问题,但在我的情况下,它运作正常。这是我的代码:
创建了一个searchController
fileprivate let searchController = UISearchController(searchResultsController:nil)
在viewDidLoad()中:
searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false searchController.searchBar.placeholder = kSearchPlaceholder searchController.searchBar.scopeButtonTitles = [kCategory,kAuthor,kPicture] searchController.searchBar.delegate = self definesPresentationContext = true
if #available(iOS 11.0,*){ navigationItem.searchController = searchController } else { tableView.tableHeaderView = searchController.searchBar }
很高兴。