At startup, open the specified ViewController

前端 未结 1 1250
囚心锁ツ
囚心锁ツ 2021-01-28 10:31

I have two VC (ViewController, SettingsVC, VC2).

How can I make it so that when you turn on the Switch

相关标签:
1条回答
  • 2021-01-28 11:20

    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")
    
    0 讨论(0)
提交回复
热议问题