how can i make headerView scroll (not stay on the

2020-06-08 07:18发布

in plainsytle tableview , we set headerViews for each section by delegate method

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section 

so,when i scrolling up tableview , the first section's headerView is always showing on the top of tableview before the section totally disappear on the tableview , then the second section's headerView will show on the top of tableview instead . so my question is how can i make headerView scroll accompanying with uitableViewCell , just like group style tableview ?

8条回答
唯我独甜
2楼-- · 2020-06-08 07:28

I had the same issue and when i browsed i came to this link See The accepted answer from and I came to conclusion that you need to set tableViewHeader Style to Group and it works Charm.

查看更多
放荡不羁爱自由
3楼-- · 2020-06-08 07:29

You can disable scrolling sectionHeader by changing the table property to -

UITableViewStyleGrouped

You have to set it on the initialisation of UITableView.

  • Set from StoryBoard

OR

UITableView* table = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped]; 
查看更多
▲ chillily
4楼-- · 2020-06-08 07:30

subclass the UITableView and override this method

- (BOOL)allowsHeaderViewsToFloat{
    return NO;
}

same for footer

- (BOOL)allowsFooterViewToFloat{
    return NO;
}

But I think that this is a private API ... You will not be able to submit it to the AppStore

If you will upload it to the AppStore; Then you have two other options

  1. Adding a normal cell instead of the section header
  2. If you have only one section, then you can simply use table header instead of section header
查看更多
萌系小妹纸
5楼-- · 2020-06-08 07:46

Change the UITableViewStyle of the table from UITableViewStylePlain to UITableViewStyleGrouped, this will make the header scroll up with cells.

查看更多
Evening l夕情丶
6楼-- · 2020-06-08 07:48

Just change style of table from "Plain" to "Grouped".

查看更多
We Are One
7楼-- · 2020-06-08 07:54

if you ve more than one section, you can customize it using some thirdt party API

else you can try this using Grouped table instead of plain tableView.

Try like this when you assign custom view as tableView Header view it becomes header view for table and it will scroll with the table view

 -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *sectionView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 200)];

        tableView.tableHeaderView =sectionView;

        return sectionView;
    }
查看更多
登录 后发表回答