如何在 UITabBarController 中插入 UINavigationController

发布于 2024-11-06 03:30:56 字数 869 浏览 1 评论 0原文

如何在 UITabBarController 中插入 UINavigationController

目前,我在应用程序委托内有主 UITabBarController 和声明(因此选项卡是主要的),

self.window.rootViewController = self.tabBarController;

并且在其中一个选项卡内我想插入 UINavigationController,但无法获取它。

代码的构造如下:

  1. MainWindow.xib ,其中包含 UITabBarController 对象,其中选项卡类型为 UINavigationController (指向 < code>NavigationHistory.xib) - 屏幕截图:无效链接
  2. NavigationHistory.xib 仅包含 UINavigationController,其中指向 History.xib
  3. History.xib 的视图仅具有 UITableView 元素 - 屏幕截图:无效链接

现在 UIViewController 不显示我的 View1 视图,我不知道为什么会这样。也许你有任何线索?或者指出完成此类配置的位置。

How to insert UINavigationController inside UITabBarController.

Currently I have main UITabBarController with declatarion inside application delegate like this (so tab is main)

self.window.rootViewController = self.tabBarController;

And inside one of tabs I want to insert UINavigationController, and can't get it.

The code is contructed like this:

  1. MainWindow.xib with UITabBarController object with tab typed as UINavigationController (point to NavigationHistory.xib) - screenshot: invalid link
  2. NavigationHistory.xib contains only UINavigationController where view point to History.xib
  3. History.xib have only UITableView element - screenshot: invalid link

And now UIViewController doesn't display my View1 view, and I have no clue why it may be. Maybe you have any clue? or point me to the place where such configuration is done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌吟 2024-11-13 03:30:56

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

Write a code in appdelegate.m file.....

- (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;
}
泅人 2024-11-13 03:30:56

将控制器对象添加到 UINavigationController,并将该 navigationcontroller 对象添加到 UITabBarController

Add your controller object to UINavigationController, and add that navigationcontroller object to UITabBarController

找个人就嫁了吧 2024-11-13 03:30:56

UINavigationController 是 UIViewController 的子类, UITabBarController 需要 UIViewController 数组(因此 UINavigationController );这告诉我,我可以为 UITabBarController 提供一个 UINavigationControllers(或其子类)数组,以提供所需的交互。

参考: https://developer.apple.com/library/ios/文档/UIKit/Reference/UINavigationController_Class/

https:// developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/

UINavigationController is a subclass of UIViewController, a UITabBarController expects an array of UIViewControllers (and therefore UINavigationController ); this tells me me that I can give a UITabBarController an array of UINavigationControllers (or sublasses thereof) giving the desired interaction.

Ref : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/

度的依靠╰つ 2024-11-13 03:30:56
- (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;

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文