2012-07-01 131 views

回答

0

你可以做的是將一個UIToolBar到你的故事板控制器和設置按鈕,你想在那裏的行動。你可以讓所有的控制器擴展成相同的基類,不必重複你的代碼,也可以在代碼中實例化這個工具欄,如果你覺得它更令人愉快。

問題將在於使用導航,因爲導航欄將替換/重疊此工具欄。

UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)]; 

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Title" 
                  style:UIBarButtonItemStyleBordered 
                  target:self 
                  action:@selector(myAction:)]; 


[myToolbar setItems:[NSArray arrayWithObjects:myButton, nil]]; 

[self.view addSubview:myToolbar]; 
+0

我不需要使用導航。我只是想要一個地方放置設置按鈕,看起來不錯,可以從任何選項卡訪問。 –

+0

那麼在這種情況下,我提出的解決方案將不會出現問題,請嘗試一下並讓我知道。 – 8vius

+0

我用一小段代碼編輯了我的答案,只需在界面構建器中完成相同的操作,然後用控制拖拽 – 8vius

0

在AppDidFinishLaunching:

Add Your TabBarcontroller (rootViewController) for UINavigationController 

現在添加下面的設置按鈕例子的導航欄

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
style:UIBarButtonSystemItemDone target:nil action:nil]; 

navigationCOntroller.navigationItem.rightBarButtonItem = rightButton 

rightButton將是可見的throught應用

0

如果你只是想放置帶有設置按鈕的導航欄,可以使用U從任何視圖進行訪問ITabBarController你可以在AppDelegate中做這樣的事情 - >

YourViewController1 *yourVC1 = [YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil]; 
UINavigationController *yourNVC1 = [[UINavigationController alloc] initWithRootViewController:yourVC1]; 

YourViewController2 *yourVC2 = [YourViewController2 alloc] initWithNibName:@"YourViewController2" bundle:nil]; 
UINavigationController *yourNVC2 = [[UINavigationController alloc] initWithRootViewController:yourVC2]; 

UITabBarController *tabBC = [[UITabBarController alloc] init]; 
[tabBC setViewControllers:[NSArray arrayWithObjects:yourNVC1, yourNVC2, nil]]; 

self.window.rootViewController = tabBC; 

你應該在所有視圖上都有一個帶有導航欄的標籤欄。現在,將設置按鈕放置在導航欄中,將其添加到您想要顯示設置按鈕的視圖控制器中的viewDidLoad方法 - >

UIBarButtonItem *selectBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(selectorName:)]; 
self.navigationItem.rightBarButtonItem = selectBarButton;