【问题标题】:how to display search box in UITable view when user scroll in UPWard direction after scrolling in downward direction?当用户向下滚动后向上滚动时,如何在表格视图中显示搜索框?
【发布时间】:2017-10-24 05:41:45
【问题描述】:

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

【问题讨论】:

  • 你可以通过实现UIScrollViewDelegate来跟踪滚动
  • @LalKrishna 是的,我正在使用这些方法 scrollViewDidScroll:(UIScrollView *)scrollView 但我没有在满足某些条件时如何显示搜索栏。

标签: ios objective-c uitableview uiscrollview uisearchcontroller


【解决方案1】:

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

类 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
}

}

【讨论】:

  • 谢谢,但由于我正在使用目标 c 语言,所以我需要在目标 c 中回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 2019-04-01
  • 2014-01-12
  • 1970-01-01
  • 2014-11-23
相关资源
最近更新 更多