I have an app with a navigation bar at the top. On one view that is a subclass of UITableView, I add a UIToolbar beneath the UITableView with the following code:
UIToolbar *toolbar = [[UIToolbar alloc] init];
[toolbar sizeToFit]; // Set the toolbar to fit the width of the app
CGFloat toolbarHeight = [toolbar frame].size.height; // Calculate the height of the toolbar
CGRect rootViewBounds = self.parentViewController.view.bounds;
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
CGRect rectArea = CGRectMake(0, toolbarHeight, rootViewWidth, toolbarHeight);
[toolbar setFrame:rectArea];
[self.navigationController.view addSubview:toolbar];
The problem is that the toolbar is “on top” of the UITableView and is masking over the top of the contents of the first row in the UITableView. What I really want is for the table view to “start” beneath the UIToolbar.
How do I make this work appropriately?
Gracias,
Jose
I agree with nonamelive, but if there is a reason to need the logic as you described. You should make the view a plain view with both a UITableView subview and a toolbar subview and set their frames accordingly to position them as you want.
Another option if you wish for the toolbar to scroll along with the other table content is to make the table’s headerView the toolbar.