Reputation: 11157
I have a table view and have attached to its tableHeaderView a UISegmentedControl. How can I make the tableHeaderView fixed so that i can always view the UISegmentedControl in the same position even when i am scrolling the table view?
Upvotes: 11
Views: 24347
Reputation: 10358
First lower the tableview's frame (make space on top of tableview). Then during scrollViewDidscroll, fix the tableviewheader properly, so it doesn't scroll with it.
That's the summary of it.
Upvotes: 1
Reputation: 7807
To expand on @mskw's answer:
You can use the UITableViewController (keep the niceties such as UIRefreshControl support and keyboard avoidance). You just have to embed your toolbar in a plain view and place that in your tableHeaderView. Then implement this scroll view delegate method to lock.
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.toolbarContainerView.frame;
rect.origin.y = MIN(0,scrollView.contentOffset.y + scrollView.contentInset.top);
self.toolbarContainerView.frame = rect;
}
Note that if you also use section headers you will have to send those views behind your tableHeaderView otherwise they will float over the tableHeaderView.
Upvotes: 1
Reputation: 4932
tableView:ViewForHeaderInSection:
is your option to achieve your task. In plain table this will somehow looks like Address Book app with first char of name in section, but you will have your segmented control
Upvotes: 7
Reputation: 839
I would suggest placing the UISegmentedControl in a separate view on top of the UITableView rather than in the tableHeaderView. You might also want to set yourTable.bounces = NO;
in order to keep the header view from bouncing when you get to the top of the table.
Upvotes: 1