在启动时,打开指定的ViewController

我有两个VC( ViewControllerSettingsVCVC2 )。

我怎么能这样做,当你打开开关 (位于SettingsVC )当应用程序启动它将显示VC2

默认是ViewController

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; } 

设置isSwitchOnSettingsVC这样 –

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