Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make header of a plain UITableView Scroll with the table

I was wondering if there was any way to allow the tableview header of a plain table to scroll with the table?

I am currently using the following method to add my header.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
like image 907
Zhen Avatar asked Sep 20 '11 10:09

Zhen


People also ask

Should I use a scroll view or a UITableView?

For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views. The code of the table view data source often ends inside view controllers when it should go into a separate class.

Why use a UITableView instead of a Tableview?

Table views are more versatile than you might think. For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views.

What is uitableviewheaderfooterview in iOS?

Introduced in iOS 6, UITableViewHeaderFooterView takes the reuse functionality of table view cells and makes it available to section headers and footers. You can either use it directly or create a subclass to customize its appearance.

How does a table view scroll back to a specific row?

When the user scrolls back to a row, the table view will request its data again. The tableView(_:numberOfRowsInSection:) method tells the table view how many elements a section contains. The table view uses this information to prepare its scrolling area and display a scroll bar of the appropriate size.


1 Answers

Actually the tableHeaderView scrolls with table. This is not the case for section header views. If you have only one section then you can have the header view as tableHeaderView.

table.tableHeaderView = aUiView;

If you have more than one sections and all of them have their own header views, then you have no choice than leaving the header views behave in their own ways. Or, you can imitate the header view by making/configuring/customizing the first row of each section look like header view and remove the actual section header views.

like image 105
EmptyStack Avatar answered Oct 14 '22 16:10

EmptyStack