2016-10-13 40 views
-1

我有一個基於主/細節的iPhone應用程序。如果不使用標籤式導航風格的應用程序,我該如何在導航控制器的底部創建一個持久按鈕(我希望在每個視圖上都有)。請線框(其加號按鈕)。我嘗試在底部的工具欄中添加一個按鈕欄項目,但由於某種原因,它不會顯示出來。我使用的xcode 8和IOS 10.如何在導航控制器底部創建持久按鈕?

enter image description here

參考我創建的自定義導航控制器類和插入下面的代碼

#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]; 

} 

然後我使工具欄上的界面生成器可見...工具欄顯示和顏色設置代碼,但按鈕不會出現

+0

「我試着在底部添加一個按鈕欄項目到工具欄,但由於某些原因,它不會出現」如果解決方案會做,你應該問自己的原因_is_什麼。不幸的是,你選擇了不顯示代碼,所以不可能提供幫助。 – matt

+0

我添加了代碼 – user379468

+0

你的代碼沒有意義。導航控制器沒有工具欄項目;它的孩子呢。您需要在所有此導航控制器的子項中設置「self.navigationItem.toolbarItems」。我的解決方案可能對你更好。 – matt

回答

2

一個簡單的解決辦法是嵌入到你的UINavigationController在自定義父視圖控制器。這意味着導航控制器的視圖是父視圖控制器視圖的子視圖。這意味着你可以添加另一個子視圖控制器的視圖,按鈕。

+0

根視圖實際上是一個分割視圖控制器,父視圖的基類是什麼? – user379468

+0

「根視圖實際上是一個分割視圖控制器」。在這種情況下,您可以將分割視圖控制器嵌入到自定義父視圖控制器中。這在任何情況下都是不常見的。當然,你將不得不考慮如何讓這個界面在iPad上工作(擴展分割視圖控制器)。 – matt