当用户向下滚动后向UPWard方向滚动时,如何在UITable视图中显示搜索框



当用户向下滚动(+y 轴)后,当用户向上滚动(-y 轴)时,我想在视图顶部显示搜索框。我是IOS的新手,所以我现在不知道该怎么做。请使用客观 c 语言回答。

使用此代码,希望对您有所帮助

类 TableViewController : UITableViewController {

var searchBar:UISearchBar?

override func viewDidLoad() {
    super.viewDidLoad()
    searchBar = UISearchBar(frame: CGRect(x: 0, y: 44, width: UIScreen.main.bounds.width, height: 44))
    view.addSubview(searchBar!)
    tableView.tableHeaderView = searchBar
    //navigationController?.navigationBar.prefersLargeTitles = true
    self.title = "nbbnbb"
    self.navigationItem.hidesSearchBarWhenScrolling = false
    tableView.setContentOffset(CGPoint(x: 0, y: 88), animated: true)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 30
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellid", for: indexPath)
    cell.textLabel?.text = "hello"
    return cell
}

}

最新更新