'hideUISearchBarWhenScrolling'-属性不适用于tableView作为属性 [英] 'hideUISearchBarWhenScrolling'-Property not working with tableView as property
本文介绍了'hideUISearchBarWhenScrolling'-属性不适用于tableView作为属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了新的Swift4/iOS11可能性,并遇到了 hideSearchBarWhenScrolling
在UIViewController中不能作为属性使用tableView的问题.
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.
在UITableViewController中,它像应该正常工作一样工作.
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)
])
}
}
谢谢
推荐答案
像这样使用:
navigationItem.hidesSearchBarWhenScrolling
这篇关于'hideUISearchBarWhenScrolling'-属性不适用于tableView作为属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文