如何在UITabBarController中插入UINavigationController
如何在UITabBarController
中插入UINavigationController
。如何在UITabBarController中插入UINavigationController
目前,我有主UITabBarController
里面应用程序委托declatarion这样的(所以标签是主要的)
self.window.rootViewController = self.tabBarController;
而且里面一个选项卡,我想插入UINavigationController
,并不能得到它。
的代码池莉构建是这样的:
-
MainWindow.xib
与UITabBarController
与标签对象类型为UINavigationController
(指向NavigationHistory.xib
) - 截图:无效链路 -
NavigationHistory.xib
仅包含UINavigationController
其中查看指向History.xib -
History.xib
只有UITableView
元素 - 屏幕截图:无效链接
现在UIViewController
不显示我的视图1视图,我不知道为什么它可能是。也许你有任何线索?或者将我指向完成这种配置的地方。
解释写appdelegate.m文件中的代码.....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSMutableArray *Mutablearray = [[NSMutableArray alloc] init];
UIViewController *1st_View = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:1st_View];
[Mutablarray addObject:Navigation];
UIViewController *2nd_View = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:2nd_View];
[Mutablearray addObject:Navigation];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = Mutablearray;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
控制器对象添加到UINavigationController的,并添加navigationcontroller对象的UITabBarController
的UINavigationController是一个UIViewController的子类,UITabBarController需要一个UIViewControllers数组(因此UINavigationController);这告诉我,我可以给UITabBarController一个UINavigationControllers(或其子类)的数组,给出所需的交互。
编号:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tab = [[UITabBarController alloc] init];
SimpleTableViewController *tableView = [[SimpleTableViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView];
UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:0];
nav1.tabBarItem = item;
AboutViewController *about = [[AboutViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:about];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
nav2.tabBarItem = item2;
tab.viewControllers = @[nav1,nav2];
self.window.rootViewController = tab;
[self.window makeKeyAndVisible];
return YES;
}
只有一半,一年后和链接已经失效。 iOS肯定会迅速发展! – JOM 2012-02-23 10:55:34
我更新了链接;-) – Marcin 2012-02-24 11:54:11