简体   繁体   English

UITableView标题视图滚动

[英]UITableView Header View Scrolls

I am using a header view, not section header, with my UITableView. 我正在使用标题视图,而不是节标题,使用我的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. 只需将您想要的视图添加为表视图的同级视图(tableView的superView的子视图),并将其放置在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). 对于固定的标题视图,不要使用self.tableView.tableHeaderView(这个是可滚动的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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