如何在UINavigationController
内插入UITabBarController
。
目前我在应用程序委托中有main UITabBarController
和prottarion(所以tab是main)
self.window.rootViewController = self.tabBarController;
在其中一个标签中,我想插入UINavigationController
,但无法获取它。
代码构造如下:
MainWindow.xib
与UITabBarController
对象,其中的标签键入为UINavigationController
(指向NavigationHistory.xib
) - 屏幕截图:无效链接 NavigationHistory.xib
仅包含UINavigationController
,其中的视图指向History.xib History.xib
只有UITableView
元素 - 屏幕截图:无效链接 现在UIViewController
没有显示我的View1视图,我也不知道为什么会这样。也许你有任何线索?或者指向我进行此类配置的地方。
答案 0 :(得分:9)
答案 1 :(得分:0)
在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;
}
答案 2 :(得分:0)
将您的控制器对象添加到UINavigationController,并将该navigationcontroller对象添加到UITabBarController
答案 3 :(得分:0)
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/
答案 4 :(得分:0)
- (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;
}