使UIViewController在Navigation Controller之外 [英] Make UIViewController outside Navigation Controller

查看:60
本文介绍了使UIViewController在Navigation Controller之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题要问你.我正在使用这个具有演练/教程屏幕以及登录屏幕的应用程序.在每个屏幕上都有一个按钮,用于跳过该部分并直接使用该应用,而无需完成注册(您知道,这样人们可以在登录前进行测试).

i have a question for you. I'm working on this app that has a walkthrough/tutorial screens and also login ones. On each of this screens there is a button to skip this part and go directly to use the app, without completing the registration (you know, so that people can test it before signing-in).

您可以看到我正在使用情节提要. NowPlaying04 ViewController实际上是应用程序本身.显然,当用户将成为注册用户时,我也应该能够直接跳回到该屏幕,而无需跳过演练和登录过程.

As you can see i'm using Storyboards. The NowPlaying04 ViewController is actually the app itself. Obviously, when the user will be a registered one, i should also be able to jump right back to that screen, skipping the walkthrough and signin process.

第一个问题是:构造此结构的最佳方法是什么?

The first question is: how is the best way to structure this?

第二个问题是:如何在导航控制器之外制作ViewController.如您现在所见,原因是NowPlaying04 ViewController继承了顶部导航栏.这是我不想要的东西.我不需要.

The second quesion is: how i can make a ViewController outside that Navigation controller. Cause as you can see now, the NowPlaying04 ViewController inherits the top navigation bar. Which is a thing that i don't want. I don't need that.

我希望你已经理解了我的问题.我将不胜感激.我以编程方式或通过拖拉东西来解决所有问题.重要的是它可以正常工作! :-)

I hope that you have understood my question. I'll appreciate any help. Programmatically or by dragging stuff around, i'm ok with all the solutions. The important thing is that it works correctly! :-)

推荐答案

因此,我也许可以使用AppDelegate.m找到解决此问题的方法.如果您使用的是Storyboards,则无需在AppDelegate.h中导入ViewController类,因为您使用的是StoryboardID来引用它们.看起来像这样:

So I maybe found a solution to this issue, using the AppDelegate.m. If you're using Storyboards, you don't need to import in the AppDelegate.h the ViewController classes, cause you're referencing them using StoryboardID. It looks something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    BOOL userLoggedIn = NO;
    if (userLoggedIn) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"NowPlaying04"];
        [self.window setRootViewController:controller];
    } else {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Start00"];
        [self.window setRootViewController:controller];
    }
    [self.window makeKeyAndVisible];

    // Override point for customization after application launch.
    return YES;
}

显然,您需要通过InterfaceBuilder/Storyboard属性在视图控制器上设置标识符.为BOOL变量userLoggedIn设置不同的值时,应用会加载相对的rootViewController.

Obviously you'll need to set identifiers on the view controllers through the InterfaceBuilder/Storyboard properties. Setting a different value to the BOOL variable userLoggedIn the app loads with the relative rootViewController.

现在,情节提要板看起来像这样:

Now the Storyboard looks like this:

更有条理. isInitialViewController在NowPlaying04屏幕上被标记.但是AppDelegate会根据isLoggedIn BOOL变量决定是否要转到它,还是切换到NavigationController(ID为Start00).

Which is much more organized. isInitialViewController is flagged on the NowPlaying04 screen. But the AppDelegate decides if to go to it or rather switch to the NavigationController (with ID Start00), based on the isLoggedIn BOOL variable.

感谢@НаильГалиаскаров使用不同的rootViewControllers的想法.

Thanks to @НаильГалиаскаров for idea of using different rootViewControllers.

这篇关于使UIViewController在Navigation Controller之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆