简体   繁体   English

UITableView将tableHeaderView和sectionHeaderView放在顶部

[英]UITableView stick tableHeaderView and sectionHeaderView together on top

I'm using plain-style UITableView with sections, which have sectionView's. 我正在使用带有sectionView的节的纯风格UITableView So, i will put UISearchBar as table-header-view and i need it was always visible on the top, but keep scrollable behaviour when user scroll down. 因此,我将UISearchBar为table-header-view,我需要它始终在顶部可见,但是当用户向下滚动时,保持滚动状态。

There's a picture how it looks like 有一张图片看起来像

在此处输入图片说明

So, i need to show HeaderView between navigation bar and section 2..3..N when scroll. 因此,滚动时我需要在导航栏和2..3..N节之间显示HeaderView Header view should stick to navigation bar, and section header view should stick to the header view. 标题视图应坚持导航栏,而节标题视图应坚持标题视图。

在此处输入图片说明

I tried next methods: 我尝试了下一种方法:

@implementation MyTableViewController

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGRect rect = self.tableHeaderView.frame;
    rect.origin.y = MIN(0, self.tableView.contentOffset.y);
    self.tableHeaderView.frame = rect;
}

and

@implementation MyTableView

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGRect rect = self.tableHeaderView.frame;
    rect.origin.y = MIN(0, self.contentOffset.y);
    self.tableHeaderView.frame = rect;
}

But get no results. 但是没有结果。

You,Maby don't use UIScrollViewDelegate 您,Maby不要使用UIScrollViewDelegate

scrollView.delegate = self

and if you want use scrollView In StoryBoard - connect it there, 如果要在StoryBoard中使用scrollView,请在此处进行连接,

you could fully show your code in the class UITableView ? 您可以在类UITableView完全显示您的代码?

and use ViewDidLoad !!! 并使用ViewDidLoad !!!

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

相关问题 对 UITableView 的 tableHeaderView 使用约束,tableHeaderView 出现在单元格顶部 - Using constraints with tableHeaderView of UITableView, tableHeaderView appears on top of cells 如何在UITableView上添加一个滚动在一起的视图,但在滚动后粘到顶部 - How to add a view on top of UITableView that scrolls together, but stick to top after scrolling 带有TableHeaderView的UITableView不会滚动到状态栏上的顶部 - UITableView with TableHeaderView wont scroll to top on status bar tap 如何将UITableView的顶部粘贴到UISearchBar的底部? - How to stick top of the UITableView to the bottom of the UISearchBar? UITableView tableHeaderView 以编程方式自动布局 - UITableView tableHeaderView autolayout programmatically 设置自定义UITableView tableHeaderView - Setting a custom UITableView tableHeaderView tableHeaderView位于第一个单元格的顶部 - tableHeaderView on top of first cell 如何不使用tableHeaderView属性将UISearchBar添加到UITableView的顶部? - How can I add a UISearchBar to the top of a UITableView without using the tableHeaderView property? UITableView tableHeaderView用户交互无法正常工作 - UITableView tableHeaderView user interaction not working 在故事板中创建标题时将 UITableView 标题视图粘贴到顶部 - Stick UITableView header view to top when creating header in storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM