Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 默认Segue到ViewController_Swift_Xcode - Fatal编程技术网

Swift 默认Segue到ViewController

Swift 默认Segue到ViewController,swift,xcode,Swift,Xcode,我对斯威夫特比较陌生,步履缓慢 下面是我的代码: let defaultName = UserDefaults.standard override func viewDidLoad() { super.viewDidLoad() let getTheme = defaultName.integer(forKey: "theme") as Int if getTheme == 1{ self.performSegue(withIdentifier: "d

我对斯威夫特比较陌生,步履缓慢
下面是我的代码:

let defaultName = UserDefaults.standard

override func viewDidLoad() {
    super.viewDidLoad()
    let getTheme =  defaultName.integer(forKey: "theme") as Int
    if getTheme == 1{
        self.performSegue(withIdentifier: "darkVC", sender: self)
    }else
        if getTheme == 2{
            self.performSegue(withIdentifier: "lightVC", sender: self)
        } else {
            //Do nothing
    }
}

@IBAction func theme_Selection(_ sender: UIButton) {
    defaultName.set(sender.tag, forKey: "theme")

}
视图控制器:

我正在尝试保存用户选择(暗或亮)并在我的UserDefault中切换到相应的Viewcontroller。不幸的是,它确实保存了UserDefault,并一直返回此Viewcontroller供用户选择

我已将按钮标记为1和2,并将它们分组到
@IBAction func主题\u选择中

你知道我在这里遗漏了什么吗?
提前感谢您提供的任何解决方案。

viewDidLoad
中无法
performSegue
。视图尚未附加到窗口。尝试将实现移动到
viewdideappear

无法在
viewdideload
中执行
performSegue
。视图尚未附加到窗口。尝试将您的实现移动到
viewdide

什么是
getVal
?顺便说一下,将
删除为Int
整数(forKey
始终返回
Int
。删除应用程序表单模拟器并重新安装,它会工作。@瓦迪安谢谢,编辑了更正。我将
删除为Int
。是否应重新分配
defaultName.integer
?很难理解你的问题是什么。你能重新表述一下你的问题吗?不成功:(仍然是。什么是
getVal
?顺便说一下,将
作为Int
整数删除。)(forKey
始终返回
Int
。删除应用程序表单模拟器并重新安装,它会工作。@瓦迪安谢谢,编辑了更正。我将
删除为Int
。是否应重新分配
defaultName.integer
?很难理解你的问题是什么。你能重新表述一下你的问题吗?不成功:(仍然。天才。现在工作。完全有意义。非常感谢。天才。现在工作。完全有意义。非常感谢。