Stunner
Stunner

Reputation: 12224

Adding Toolbar to Navigation Controller

Sup fellas, so I have a navigation controller with a table view to which I am trying to add a tool bar, however, the way I have implemented it causes the very last row in the table to be hidden behind the tool bar. I will try to illustrate via pictures:

Table view scrolled to the bottom without tool bar:

alt text

Table view scrolled to the bottom with tool bar(notice how the last "Vendor" row is concealed behind the tool bar):

alt text

I was following this guide and this is what I ended up doing for my implementation:

alt text

As you can see I have a "View" instead of "Window" to work with. Here is the code I have for displaying the tool bar:

- (void)viewDidLoad {
    [super viewDidLoad];
 [self.view addSubview:self.navigationController.view];
 [self.view addSubview:toolbar];
 [self.navigationController.view setFrame:self.view.frame];
}

It seems to me that I need to adjust the frame of the navigation controller frame to compensate for the tool bar being at the bottom. This is where I am stuck. How would I go about doing this? Any help appreciated!

Upvotes: 3

Views: 9320

Answers (2)

ughoavgfhw
ughoavgfhw

Reputation: 39925

If you add the toolbar to the navigation controller, it will automatically resize itself. Just check this box in IB.

Check "Shows Toolbar" box in IB

Upvotes: 4

Jacob Relkin
Jacob Relkin

Reputation: 163308

I've had a similar issue before.

You need to adjust the height of your UINavigationController's view to be exactly 44 pixels less.

This should do it:

- (void)viewDidLoad {
   [super viewDidLoad];
   [self.view addSubview:self.navigationController.view];
   [self.navigationController.view setFrame:CGRectMake(self.view.frame.x, self.view.frame.y, self.view.frame.width, self.view.frame.height - 44.0f)];
   [self.view addSubview:toolbar];
}

Upvotes: 4

Related Questions