我有一個基於主/細節的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