简体   繁体   中英

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:

替代文字

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

替代文字

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

替代文字

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!

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];
}

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

在IB中选中“显示工具栏”框

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM