简体   繁体   English

如何在滚动时将tableView显示到顶部

[英]How to show tableView to top when scrolled

In my project, In the view 'Top' side is for one UIView and below it a tableView. 在我的项目中,在视图中“顶部”侧是一个UIView,下面是一个tableView。 I want to show tableView to top when scrolled and hide the tableView. 我想在滚动时将tableView显示到顶部并隐藏tableView。

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
    self.topView.isHidden = true  }

Please give me solution for how to show tableView to top when tableView scrolled. 请给我解决方案,以便在tableView滚动时如何将tableView显示到顶部。 Below is the screenshot [![enter image description here][1]][1] 下面是截图[![在此处输入图像描述] [1]] [1]

in this view bottom is tableView and top is UIView. 在这个视图中底部是tableView,顶部是UIView。 Below is the storyboard screenshot. 以下是故事板截图。 在此输入图像描述

The simplest solution is to set that topView as tableHeaderView . 最简单的办法是设置topView作为tableHeaderView

self.tableView.tableHeaderView = topView

Now when you scroll the tableView topView will goes up with it. 现在,当您滚动tableView topView将会启动它。 Also no need to implement scrollViewDidScroll now. 现在也不需要实现scrollViewDidScroll

Select your tableview in your Controller of Storyboard Controller of Storyboard 选择您的tableview

  1. Select your TableView 选择您的TableView
  2. Go to Attributes Inspector on the right panel of Utilities 转到Utilities右侧面板上的Attributes Inspector
  3. Set Style to Grouped Style 设置Grouped

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM