【问题标题】:Presenting NavigationalViewController in TabbarController在 TabbarController 中呈现 NavigationalViewController
【发布时间】:2016-10-12 17:22:26
【问题描述】:

我正在开发一个 iOS 应用程序,其结构是基于标签栏的。我的根视图控制器是 TabBarController 但如果第一次启动应用程序,我需要在应用程序的开头显示一个导航视图控制器。我实现了一个 FlowViewController 来控制应用程序的流程。在 FlowViewController 中,我创建 TabBarController 并将其分配为 rootviewcontroller。

如何在应用程序的开头显示导航视图控制器,然后显示 TabBarController。

流视图控制器

TabBarViewController *rootVC = [[TabBarViewController alloc] init];
rootVC.delegate = self;
rootVC.tabBar.translucent = NO;
self.rootViewController = rootVC;

在 AppDelegate 中,didFinishLaunchingWithOptions

self.flowController = [[FlowController alloc] init];

self.window = [[UIWindow alloc] initWithFrame:[ [UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.flowController.rootViewController;

[self.window makeKeyAndVisible];

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    如果应用程序通常需要设置屏幕,我将使用 NSUserDefaults 检查该应用程序之前是否已在 viewDidLoad() 中启动。如果没有,那么我将展示设置 viewController。用户完成设置过程后,将某些内容添加到 NSUserDefaults 中,以便在启动应用程序时知道用户已经完成了该过程。

    【讨论】:

      【解决方案2】:

      在我的应用程序中,我将 UINavigationController 设置为根视图控制器。然后我将 TabBarController 添加为 UINavigationController 的子项。

      根据需要在 StoryBoard 中设计视图控制器。为 UITabBarController 设置 Storyboard id 并使用该 Storyboard 标识符调用标签栏控制器。

      -(IBAction)LoginAction:(id)sender{

      UITabBarController *loadTabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarViewControllerID"];
      [self.navigationController pushViewController:loadTabBar animated:YES];
      

      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-23
        • 2014-01-14
        • 1970-01-01
        • 2020-01-25
        • 2023-03-20
        • 1970-01-01
        • 2020-06-29
        • 2017-07-03
        相关资源
        最近更新 更多