Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UITableView table header scrolling issue

lukeirvinlukeirvin Posts: 388Registered Users @ @
Here's a breakdown of how my UIView is setup for my UIViewController:

There's a UIView at the top. This is my container view that will have other objects in it.
Below this view is my UITableView with a custom header.

I want to table view with the header to scroll over the UIView at the top, have the table header stick to the top under the navigation bar, and then the table view will scroll.

Right now I'm close to getting the effect I want, but I can't get my table header to stick to the top under my navigation bar.

Here's my code:
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [self.myTableView setContentInset:UIEdgeInsetsMake(self.containerView.bounds.size.height, 0.f, 0.f, 0.f)];
    [self.myTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];

    float headerImageYOffset = 88 + self.containerView.bounds.size.height - self.view.bounds.size.height;
    CGRect headerImageFrame = self.containerView.frame;
    headerImageFrame.origin.y = headerImageYOffset;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // This is made in Interface Builder
    return self.headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat scrollOffset = -scrollView.contentOffset.y;
    CGFloat yPos = scrollOffset - _containerView.bounds.size.height;
    _containerView.frame = CGRectMake(0, yPos, _containerView.frame.size.width, _containerView.frame.size.height);   
}

Replies

Sign In or Register to comment.