如何设置初始故事板 [英] How to set initial storyboard

查看:108
本文介绍了如何设置初始故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个故事板,其中一个默认名为主要,另一个我刚刚添加的名为管理员

I have two storyboards one of them is default called Main and the other one I have just added is called Admin.

主要用于客户,管理员用于该应用的所有者。

Main is used for customer, Admin is used for owner of the app.

I想知道如何以编程方式设置初始/主界面故事板。

I wonder how do you set initial/main interface storyboard programmatically.

PS我知道如何通过xcode更改它但不能以编程方式知道。

P.S. I know how to change it via xcode but do not know programatically.

推荐答案

您没有以编程方式设置初始故事板。

You do not set an initial storyboard programmatically.

以下是它的工作原理。您可以在主界面下的Xcode中列出主要故事板,或者您没有:

Here's how it works. Either you have a main storyboard listed in Xcode under Main Interface or you don't:


  • 如果您这样做,那就是最初的故事板,期间。该故事板在启动时自动加载,其初始视图控制器成为窗口的根视图控制器(然后自动显示界面)。

  • If you do, that is the initial storyboard, period. That storyboard is loaded automatically at launch time, and its initial view controller becomes the window's root view controller (and the interface is then displayed automatically).

如果你不要(也就是说,如果Main Interface字段为空),那么 nothing 会自动发生。由您的代码获取视图控制器,以某种方式(可能来自故事板),并使其成为窗口的根视图控制器(并显示界面)。

If you don't (that is, if the Main Interface field is empty), then nothing happens automatically. It is up to your code to obtain a view controller, somehow (possibly from a storyboard), and make its the window's root view controller (and to show the interface).

所以,总而言之,一切都是自动发生的,或者没有自动发生。没有中间状态,正如您所想象的那样,您可以通过编程方式更改内容,以便自动加载不同的故事板。

So, to sum up, either everything happens automatically or nothing happens automatically. There is no intermediate state, as you seem to imagine, in which you can programmatically change things so that a different storyboard is loaded automatically.

然而,有一种类型允许主界面故事板加载但是忽略它的中间状态。在你的应用程序:didFinishLoading ... 的实现中,你将有时做我在第二个要点中所说的事情,即加载一个不同的视图控制器并使其成为根视图控制器。这是有效的,因为我在第一个项目符号点中提到的自动内容已经已经发生应用程序:didFinishLoading ... 被调用。因此,实际上,您的代码有时会允许自动填充,有时会覆盖它。

There is, however, a kind of intermediate state where you permit the Main Interface storyboard to load but then you ignore it. In your implementation of application:didFinishLoading..., you would then sometimes do the thing I said in the second bullet point, i.e. load a different view controller and make it the root view controller. This works because the automatic stuff I mentioned in the first bullet point has already happened by the time application:didFinishLoading... is called. So, in effect, your code sometimes permits that automatic stuff and sometimes overrides it.

在我自己的代码的示例中,我们使用主界面故事板加载初始视图控制器或我们自己从故事板加载不同的视图控制器,具体取决于用户默认值中的值:

In this example from my own code, we either use the Main Interface storyboard to load the initial view controller or we load a different view controller from the storyboard ourselves, depending on a value in User Defaults:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    if let rvc = self.window?.rootViewController {
        if NSUserDefaults.standardUserDefaults().objectForKey("username") as? String != nil {
            self.window!.rootViewController = rvc.storyboard!.instantiateViewControllerWithIdentifier("root")
        }
    }
    return true
}

这篇关于如何设置初始故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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