gpt4 book ai didi

ios - 继续不运行

转载 作者:行者123 更新时间:2023-11-28 12:28:51 24 4
gpt4 key购买 nike

我正在使用 if 语句来运行 segue。我有 if 语句在它成功运行时打印一条消息。但是,segue 没有运行,我不确定为什么。

override func viewDidLoad() {
super.viewDidLoad()

firstField.delegate = self
signUpButtonOutlet.isEnabled = false
// Do any additional setup after loading the view.

let fetchRequest: NSFetchRequest<Check> = Check.fetchRequest()

do {
//go get the results
let searchResults = try getContext().fetch(fetchRequest)

//I like to check the size of the returned results!
print ("num of results = \(searchResults.count)")

//You need to convert to NSManagedObject to use 'for' loops
for check in searchResults as [NSManagedObject] {
//get the Key Value pairs (although there may be a better way to do that...
print("the value was\(check.value(forKey: "isLoggedIn"))")

if (check.value(forKey: "isLoggedIn") != nil) {
self.performSegue(withIdentifier: "loggedInTrue", sender: self)
print("if statement ran")
}


}


} catch {
print("Error with request: \(error)")
}

}

最佳答案

最好的方法是在检查用户是否已经登录后从 appDelegate 加载“loggedIn” Controller 。

因此,例如在应用委托(delegate)的 didFinishLaunchingWithOptions 方法中检查用户默认值以查看用户是否已登录

if UserDefaults.standard().bool(forKey: "logged_in") == true {

self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "YOURSTORYBOARDNAME", bundle: nil)
let loggedIn = storyboard.instantiateViewController(withIdentifier: "LOGGEDIN") as! UIViewController
self.window?.rootViewController = loggedIn
}

显然,要使它起作用,您需要在用户实际登录时将 loggedIn 变量设置为 true。像这样

UserDefaults.standard().setBool(true, forKey: "logged_in")

您必须注意的一件事是,将 YOURSTORYBOARDNAME 更改为您的实际 Storyboard,您还必须在 Storyboard中设置该 Controller 的标识符

enter image description here

关于ios - 继续不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42645044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com