3
A
回答
12
由於標籤欄控制器是一個容器視圖控制器,用於將應用程序劃分爲兩種或多種不同的操作模式,因此大多數應用程序都將導航控制器作爲子項的標籤欄控制器。
蘋果的地位是這樣的:
您在 情況下使用標籤欄控制器,你的程序 要麼呈現出不同類型的 數據或呈現 顯著不同的方式相同的數據。
這並不是說你不能做不同的事情......你主要的問題是,你已經放置在導航控制器的應用程序,你想通過程序生成標籤欄控制器。因此,我可以看到這一點的唯一方法是,您不介意每次更換導航控制器內的屏幕時,Tabbar控制器是否更改。有些應用程序可以這樣工作大多數不。
如果我上面的假設是真實的,我建議你重新考慮你的代碼,看看你是否想要追求這一發展路線。如果是這樣,您可以輕鬆創建一個TabBar控制器並將其附加到當前視圖中。
下面是代碼,我用它來創建我的設置爲我的應用程序之一:
// set up a local nav controller which we will reuse for each view controller
UINavigationController *localNavigationController;
// create tab bar controller and array to hold the view controllers
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1];
// setup the first view controller (Root view controller)
RootViewController *myViewController;
myViewController = [[RootViewController alloc] initWithTabBar];
// create the nav controller and add the root view controller as its first view
localNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
localNavigationController.navigationBar.barStyle = UIBarStyleBlack;
localNavigationController.delegate = self;
[localControllersArray addObject:localNavigationController];
// release since we are done with this for now
[localNavigationController release];
[myViewController release];
tabBarController.viewControllers = localControllersArray;
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
tabBarController.delegate = self;
tabBarController.moreNavigationController.delegate = self;
// release the array because the tab bar controller now has it
[localControllersArray release];
self.tabBarController.selectedIndex = 0;
// add the tabBarController as a subview in the window
[window addSubview:tabBarController.view];
// need this last line to display the window (and tab bar controller)
[window makeKeyAndVisible];
有,我覺得這是比較容易編程做一切,所以很多情況下。
希望這會有所幫助。
0
您必須保留對標籤欄控制器的引用。例如,您可以將它保留在App Delegate中...
相關問題
- 1. 如何以編程方式創建Tabbar
- 2. 編程方式創建的TabBar
- 3. 如何以編程方式定位TabBar
- 4. 如何以編程方式創建UIScrollview
- 5. 如何以編程方式創建UIViewController?
- 6. 如何以編程方式創建UIButton
- 7. 如何以編程方式創建NSTextField?
- 8. 如何以編程方式創建ProgressBar?
- 9. 如何以編程方式創建CustomCell?
- 10. 如何以編程方式創建NSPopover
- 11. 如何以編程方式創建GPO?
- 12. 如何以編程方式創建NSFetchedPropertyDescription?
- 13. 如何以編程方式創建UIScrollView?
- 14. 如何以編程方式創建TextView?
- 15. 如何以編程方式創建NSSearchField?
- 16. 如何以編程方式將naviagationController添加到tabBar控制器?
- 17. 以編程方式創建ViewController和awakeFromNiB?
- 18. 以編程方式增加音量
- 19. 以編程方式增加版本號?
- 20. 如何創建自定義按鈕並以編程方式添加它?
- 21. 以編程方式增加UDP緩衝區 - 它有意義嗎?
- 22. 如何以編程方式創建任何形式的按鈕?
- 23. 如何以編程方式將Android上的JVM增加到10MB?
- 24. 如何以編程方式使用Win32創建快捷方式
- 25. Eclipse RCP - 如何以編程方式創建和打開View?
- 26. 以編程方式創建C#/ SQLCE TABLE(自動增量+主鍵)
- 27. 以編程方式創建流程圖
- 28. 如何以編程方式創建一個以下的texviews?
- 29. 如何以編程方式增加iPhone音量
- 30. 如何以編程方式增加版本號?