How to embed a UITableView in a UIScrollview

后端 未结 6 634
借酒劲吻你
借酒劲吻你 2020-12-05 05:47

How can I do the following in a UIViewController (containing a tableview as a subview)

I initially have a UIViewController showing a preview section (UIView)

相关标签:
6条回答
  • 2020-12-05 05:50

    Yes,You can use "tableView:viewForHeaderInSection".

    0 讨论(0)
  • 2020-12-05 05:55

    Or you can just do these steps: 1. Disable scrolling of the tableView. 2. Set height constraint to the tableView and a IBOutlet connected to it. 3. Before you reload the data, calculate the table height. heightConstraint.constant = (heightOfTheSingleTableViewCell) * numOfRows

    0 讨论(0)
  • 2020-12-05 06:06

    You will have to embed your UITableView inside of a UIScrollView that has the size of the screen minus the navigation bar. Set the UIScrollViews background to clearColor to allow your content above the UITableView to remain visible.

    0 讨论(0)
  • 2020-12-05 06:10

    i have a solution for you,

    use only tableView is enough

    1. make the "Preview View" as the HeaderView of your tableView

    2. make the "Search Bar" as the Section Header View of your tableView

    you can make it perfectly :)

    0 讨论(0)
  • 2020-12-05 06:13

    No need for anything fancy or custom, use a UITableView and set your preview pane to be the tableHeaderView and your search field to be the section header using tableView:viewForHeaderInSection: in your UITableViewDelegate.

    The table header will scroll off the top during scroll event. Section headers float and stay visible the whole time that section if visible. If you only have 1 section, then the section header will be there the whole time.

    0 讨论(0)
  • 2020-12-05 06:14
    scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    

    It can not scroll because contentSize is not large enough. You need to increase the length to total length of your content that are on top of the scrollView.

    0 讨论(0)
提交回复
热议问题