公告
财富商城
积分规则
提问
发文
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.
Write this code in didFinishLaunchingWithOptions -
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 -
isSwitchOn
SettingsVC
UserDefaults.standard.set(true, forKey: "isSwitchOn")
最多设置5个标签!
Write this code in
didFinishLaunchingWithOptions
-Set
isSwitchOn
inSettingsVC
like this -