[英]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.