Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

ios - How do I create a persistent button on the bottom of a navigation controller?

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.

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...