How do I create a persistent button on the bottom

2019-09-19 16:28发布

问题:

I have a master / detail based iPhone app. Without using a tabbed navigation style application, how do I create a persistent button at the bottom of the navigation controller ( I want it on every view ). Please wireframe ( its the plus button ). I've tried adding a button bar item to the toolbar at the bottom, but for some reason it won't show up. I'm using xcode 8 and ios 10.

for reference I created a custom navigation controller class and inserted the following code

#import "MainNavigationController.h"

@interface MainNavigationController ()

@end

@implementation MainNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"Testing");
    // Do any additional setup after loading the view.

    NSMutableArray *buttonsArray = [[NSMutableArray alloc] init];
    UIBarButtonItem *myButton1=[[UIBarButtonItem alloc] initWithTitle:@"button 1" style:UIBarButtonItemStylePlain target:self action:@selector(toolbarButtonPressed1:)];
    [buttonsArray addObject:myButton1];
    UIBarButtonItem *myButton2 = [[UIBarButtonItem alloc] initWithTitle:@"button 2" style:UIBarButtonItemStylePlain target:self action:@selector(toolbarButtonPressed2:)];
    [buttonsArray addObject:myButton2];
    [self setToolbarItems:buttonsArray animated:YES];

    [self.toolbar setBarStyle:UIBarStyleBlack];
    [self.toolbar setItems: buttonsArray animated:NO];

}

Then I make the toolbar visible in the interface builder ... the toolbar shows and the color is set in code, but the buttons do not appear

回答1:

A simple solution would be to embed your UINavigationController in a custom parent view controller. This means that the navigation controller's view is a subview of the parent view controller's view. And that means that you could add another subview of the parent view controller's view, the button.