I have a UITableViewController embedded on a UINavigationController. This tableView is an instance of NSFetchedResultsController. I need to add a Toolbar between the Naviga
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 header you will have to send those views behind your tableHeaderView otherwise they will float over the tableHeaderView.
Use UIViewController
instead of just UITableViewController
where you can easily place other controls apart from just a UITableView
.
Hope this helps.
Technical Note TN2154: UIScrollView And Autolayout provides another solution:
Note that you can make a subview of the scroll view appear to float (not scroll) over the other scrolling content by creating constraints between the view and a view outside the scroll view’s subtree, such as the scroll view’s superview.
That is, even if a scroll view (such as a table view) modifies the subview's frame, the auto layout engine will reset it on the next layout pass.
You can make a topBar of any UIView and then pass it as the tableHeaderView. It may help you.
The approach I prefer is to use a UIViewController
at the outer level, containing your toolbar and a container view that holds the table. Then build your table in a separate UITableViewController
and wire it into the container view using an embed segue. Overall, I think this makes the code more modular and easier to follow because the high-level structure is laid out in the storyboard.
The steps to use an embed segue are as follows:
prepareForSegue
method, checking for your segue's identifier.There is an example of this in my VCollectionViewGridLayout library. Take a look at the Sort & Filter example project.
you need use UIViewController, then add tool bar and tableView instance of NSFetchedResultsController class inside it in storyboard