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?
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.
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
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.
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.
Thats the summary of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With