如何在UITabBarController中嵌入UINavigationController

4
如何在UITabBarController中嵌入UINavigationController
目前我有一个主UITabBarController,在应用程序代理中声明如下(因此选项卡是主要的):
self.window.rootViewController = self.tabBarController;

我想在其中一个选项卡中插入UINavigationController,但是无法实现。

代码构造如下:

  1. MainWindow.xib使用UITabBarController对象,并将选项卡类型设置为UINavigationController(指向NavigationHistory.xib)- 截图:无效链接
  2. NavigationHistory.xib仅包含UINavigationController,其中视图指向History.xib
  3. History.xib只有UITableView元素 - 截图:无效链接

现在UIViewController不显示我的View1视图,我不知道可能的原因。你有任何线索吗?或者指导我找到这样配置的位置。

5个回答

10

1
仅半年后,那个链接已经失效了。iOS 确实发展迅速! - JOM

0
将您的控制器对象添加到UINavigationController中,然后将该navigationcontroller对象添加到UITabBarController中。

0

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;

}


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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接