Oleg Sobolev
Oleg Sobolev

Reputation: 3376

UITableView stick tableHeaderView and sectionHeaderView together on top

I'm using plain-style UITableView with sections, which have sectionView's. 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.

There's a picture how it looks like

enter image description here

So, i need to show HeaderView between navigation bar and section 2..3..N when scroll. Header view should stick to navigation bar, and section header view should stick to the header view.

enter image description here

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.

Upvotes: 2

Views: 685

Answers (1)

Maxim
Maxim

Reputation: 63

You,Maby don't use UIScrollViewDelegate

scrollView.delegate = self

and if you want use scrollView In StoryBoard - connect it there,

you could fully show your code in the class UITableView?

and use ViewDidLoad!!!

Upvotes: 1

Related Questions