启动时,打开指定的ViewController

Posted

技术标签:

【中文标题】启动时,打开指定的ViewController【英文标题】:At startup, open the specified ViewController 【发布时间】:2017-09-04 12:43:42 【问题描述】:

我有两个 VC(ViewControllerSettingsVCVC2)。

我怎样才能使当您打开开关(位于SettingsVC)时,应用程序启动时会显示VC2??

默认为 ViewController

【问题讨论】:

您的应用中是否有任何启动画面控制器? 【参考方案1】:

将此代码写入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;

像这样在SettingsVC 中设置isSwitchOn -

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

【讨论】:

以上是关于启动时,打开指定的ViewController的主要内容,如果未能解决你的问题,请参考以下文章