How to scroll the header along with the UITableView?

前端 未结 6 1855
一整个雨季
一整个雨季 2021-02-02 07:07

I have a UITableView with a header. the problem I currently have is that the header doesn\'t scroll with the table. I need it to scroll off screen (above) when the

相关标签:
6条回答
  • 2021-02-02 07:49

    Changing the UITableViewStyle from Plain to Grouped make the section header to scroll with the other cells.

    0 讨论(0)
  • 2021-02-02 07:52

    create sectionHeader view in a new method and then add to the end:

    self.tableView.tableHeaderView = sectionHeader;
    
    0 讨论(0)
  • 2021-02-02 07:57

    if you have dynamic header view or single view select table style

    0 讨论(0)
  • 2021-02-02 08:00

    If you write tableView.tableHeaderView = sectionHeader you will lose the actual table view header.
    If you want to have table view header along with section headers you have to set UITableViewStyle property to UITableViewStyleGrouped.
    Also if you want to calculate section header height automatically you can return UITableViewAutomaticDimension in heightForHeaderInSection method like this:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return UITableViewAutomaticDimension;
    }
    
    0 讨论(0)
  • 2021-02-02 08:02

    That behavior is only common when the UITableViewStyle property of the table is set to UITableViewStylePlain. If you have it set to UITableViewStyleGrouped, the headers will scroll up with the cells.

    This answer is taken from this question.

    This solution works regardless of the number of headers.

    0 讨论(0)
  • 2021-02-02 08:03

    If you have a single header in the table then you can use tableHeaderView as below:

    tableView.tableHeaderView = Header;
    

    Or if you have multiple header in table than you need to use Group table instead of plain table.

    Thanks

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