我有一个基于主/细节的iPhone应用程序。如果不使用标签式导航风格的应用程序,我该如何在导航控制器的底部创建一个持久按钮(我希望在每个视图上都有)。请线框(其加号按钮)。我尝试在底部的工具栏中添加一个按钮栏项目,但由于某种原因,它不会显示出来。我使用的xcode 8和IOS 10.如何在导航控制器底部创建持久按钮?
参考我创建的自定义导航控制器类和插入下面的代码
#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];
}
然后我使工具栏上的界面生成器可见...工具栏显示和颜色设置代码,但按钮不会出现
“我试着在底部添加一个按钮栏项目到工具栏,但由于某些原因,它不会出现”如果解决方案会做,你应该问自己的原因_is_什么。不幸的是,你选择了不显示代码,所以不可能提供帮助。 – matt
我添加了代码 – user379468
你的代码没有意义。导航控制器没有工具栏项目;它的孩子呢。您需要在所有此导航控制器的子项中设置“self.navigationItem.toolbarItems”。我的解决方案可能对你更好。 – matt