At startup, open the specified ViewController

2020-05-06 14:10发布

I have two VC (ViewController, 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??

The default is ViewController.

1条回答
来,给爷笑一个
2楼-- · 2020-05-06 14:51

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

Set isSwitchOn in SettingsVC like this -

UserDefaults.standard.set(true, forKey: "isSwitchOn")
查看更多
登录 后发表回答