'hideUISearchBarWhenScrolling'-Property not working with tableView as property

烈酒焚心 提交于 2019-12-11 08:45:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!