Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView Header View Scrolls

I am using a header view, not section header, with my UITableView. The documentation says that the header view sits on top of the table, but my header view scrolls just like a normal row. Is there a way to make the header view always visible at the top of the table?

like image 793
Jim B Avatar asked Dec 17 '25 18:12

Jim B


2 Answers

You certainly did found the solution for this, but I'm posting it here for other people. The table view header and footer views do scroll with the rest of the rows. If you want them to have a fixed position on top, or bottom of the table view then you don't really need a header or footer view. Just add your desired view as a sibling of the table view (subview of tableView's superView) and position it on top or bottom of the tableView.

like image 187
Mihai Avatar answered Dec 20 '25 09:12

Mihai


The solution is to implement:

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

and

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

for a fixed header view, not use the self.tableView.tableHeaderView (this one is scrollable).

like image 29
Julijana Avatar answered Dec 20 '25 09:12

Julijana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!