登录后,我想记住用户,应该去主ViewController,但它没有。我试图检查我的代码是否工作,它似乎工作,但它什么也不做。我知道它是工作,因为当我写字符串“with Identifier”,它会立即给出错误,但如果我写“with Identifier”字符串错误,它会给出错误。我把print设置为“understanding”,它会说“window is nil”所有的时间。顺便说一下,在应用程序委托中,我做了:
var window: UIWindow?
下面是我的代码:
let user : String? = UserDefaults.standard.string(forKey: "username")
if user != nil {
let board : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let myTag = board.instantiateViewController(withIdentifier: "myTags") as! mainBeaconList
print("mainBeaconList: \(myTag)")
if let window = window {
print("window: \(window)")
window.rootViewController = myTag
} else {
print("window is nil")
}
}
1条答案
按热度按时间zxlwwiss1#
您可能没有设置窗口