在启动时,打开指定的ViewController [英] At startup, open the specified ViewController

查看:122
本文介绍了在启动时,打开指定的ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个VC( ViewController SettingsVC VC2 )。

I have two VC (ViewController, SettingsVC, VC2).

如何在应用程序启用开关(位于 SettingsVC )时进行设置开始它将显示 VC2 ??

How can I make it so that when you turn on the Switch(located in SettingsVC) when the application starts it would be shown VC2??

默认为 ViewController

推荐答案

将此代码写入 didFinishLaunchingWithOptions -

Write this code in didFinishLaunchingWithOptions -

let isSwitchOn = UserDefaults.standard.bool(forKey: "isSwitchOn")
if isSwitchOn {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc2 = storyboard.instantiateViewController(withIdentifier: "Your identifier")
self.window!.rootViewController = vc2;
}

设置 isSwitchOn in SettingsVC 喜欢这样 -

Set isSwitchOn in SettingsVC like this -

UserDefaults.standard.set(true, forKey: "isSwitchOn")

这篇关于在启动时,打开指定的ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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