如何在导航控制器底部创建持久按钮? [英] How do I create a persistent button on the bottom of a navigation controller?

查看:27
本文介绍了如何在导航控制器底部创建持久按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于主/细节的 iPhone 应用程序.在不使用选项卡式导航样式应用程序的情况下,如何在导航控制器底部创建一个持久按钮(我希望在每个视图上都有它).请线框(它的加号按钮).我试过在底部的工具栏中添加一个按钮栏项目,但由于某种原因它不会显示.我使用的是 xcode 8 和 ios 10.

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

推荐答案

一个简单的解决方案是将您的 UINavigationController 嵌入到自定义父视图控制器中.这意味着导航控制器的视图是父视图控制器视图的子视图.这意味着您可以添加另一个父视图控制器视图的子视图,即按钮.

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.

这篇关于如何在导航控制器底部创建持久按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆