简体   繁体   中英

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?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM