在启动时,打开指定的ViewController

时间:2017-09-04 12:43:42

标签: ios swift3 xcode8

我有两个VC( ViewController SettingsVC VC2 )。

如何在应用程序启动时打开开关(位于 SettingsVC )时显示 VC2 ...

默认为 ViewController

1 个答案:

答案 0 :(得分:0)

将此代码写入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中设置SettingsVC,就像这样 -

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