问题
I played around with the new Swift4/iOS11 possibilities and stuck with the problem that hideSearchBarWhenScrolling
isn't working with a tableView as a property in UIViewController.
In UITableViewController it's working like it should work.
What am I doing wrong? Somebody issued the same problem an has an solution for this?
class AddController: UIViewController {
let tableView: UITableView = {
let tv = UITableView()
tv.translatesAutoresizingMaskIntoConstraints = false
return tv
}()
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
navigationItem.title = "Heading"
navigationItem.searchController = searchController
navigationController?.navigationBar.prefersLargeTitles = true
}
override func viewWillLayoutSubviews() {
view.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
}
Thanks
回答1:
Use like this :
navigationItem.hidesSearchBarWhenScrolling
来源:https://stackoverflow.com/questions/46401725/hideuisearchbarwhenscrolling-property-not-working-with-tableview-as-property