【问题标题】:At startup, open the specified ViewController启动时,打开指定的ViewController
【发布时间】:2017-09-04 12:43:42
【问题描述】:

我有两个 VC(ViewControllerSettingsVCVC2)。

我怎样才能使当您打开开关(位于SettingsVC)时,应用程序启动时会显示VC2??

默认为 ViewController

【问题讨论】:

  • 您的应用中是否有任何启动画面控制器?

标签: ios swift3 xcode8


【解决方案1】:

将此代码写入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;
}

像这样在SettingsVC 中设置isSwitchOn -

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-22
    • 2021-07-24
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多