How can I do a headerView scroll (not staying at the top of the table) accompanying the UItableViewCell when I scroll through the table view

in the plainsytle table view, we set headerViews for each section using the delegation method

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

so when I scroll through the table view, the first heading of the heading is always displayed at the top of the table, before the section disappears completely in the table view, then the second heading of the heading will be displayed at the top of the table. so my question is, how can I do a headerView scroll accompanying a uitableViewCell, just like a table style in a group style?

+8
ios uitableview
source share
4 answers

submenu UITableView and override this method

 - (BOOL)allowsHeaderViewsToFloat{ return NO; } 

for footer

 - (BOOL)allowsFooterViewToFloat{ return NO; } 

But I think this is a private API ... You cannot send it to the AppStore

If you upload it to the AppStore; Then you have two more options.

  • Adding a normal cell instead of a section title
  • If you have only one section, you can simply use the table title instead of the section title
+9
source share

I had the same problem, and when I looked, I came to this link . See the accepted answer , and I came to the conclusion that you need to set tableViewHeader Style for the group and it works Charm.

+5
source share

You can disable the scroll of the Header section by changing the table property to -

 UITableViewStyleGrouped 

You must set it when initializing a UITableView.

  • Install with StoryBoard

OR

 UITableView* table = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped]; 
+4
source share

If you have multiple sections, you can configure it using third-party APIs

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

Try this when you assign a custom view as a TableView title, it becomes the table title for the 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; } 
+2
source share

All Articles