Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i make headerView scroll (not stay on the top of the tableview ) accompanying with UItableViewCell when i was scrolling tableview

Tags:

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 ?

like image 329
user3113382 Avatar asked Dec 31 '13 08:12

user3113382


People also ask

How do I scroll to the top of a tableView table?

To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.

How do I scroll the header along with UITableView?

If you want to have table view header along with section headers you have to set UITableViewStyle property to UITableViewStyleGrouped . Show activity on this post. If you have a single header in the table then you can use tableHeaderView as below: tableView.

Is tableView scrollable?

To be precise, table views and collection views are also scroll views. If you look at the documentation of the UITableView class, you will see that it descends from UIScrollView.


2 Answers

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

UITableViewStyleGrouped 

You have to set it on the initialisation of UITableView.

  • Change Table Style from Plain to Grouped on StoryBoard

OR

UITableView* table = [[UITableView alloc]initWithFrame:myFrame style:UITableViewStyleGrouped];  
like image 65
Lal Krishna Avatar answered Oct 22 '22 04:10

Lal Krishna


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

like image 45
Akshay Phulare Avatar answered Oct 22 '22 04:10

Akshay Phulare