gpt4 book ai didi

ios - 在 API 中创建 if 条件时,如何修复 swift 代码中调用 Storyboard 的速度?

转载 作者:行者123 更新时间:2023-11-29 05:44:04 27 4
gpt4 key购买 nike

我有一个API,可以检查用户名和密码是否正确,当正确返回值“1”CHK =“1”时,调用并检查值时,我用消息打印控制台,当我单击它时,消息很快就会出现但切换到主页 Storyboard需要时间,有时甚至不起作用。

if let url = urlString {
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let error = error {
print(error)
} else {
if let unwrappedData = data {

do{
//let dataString = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)!
let json = try JSONSerialization.jsonObject(with: unwrappedData, options: []) as AnyObject

if let JsonDic = json[0] as? NSDictionary
{
if let check = JsonDic["CHK"] {
if let check1 = check as? String {
if check1 == "1" {
let HomeViewControler = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
self.navigationController?.pushViewController(HomeViewControler, animated: true)
self.dismiss(animated: false, completion: nil)
print("You Are ready to login")
}else{
print("You Enterd a wrong password or Mail")
}
}
}
}

}catch{
print("There are an Error")
}

最佳答案

删除self.dismiss(animated: false, completion: nil)并更新代码

  if check1 == "1" 
{
let HomeViewControler = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
self.navigationController?.pushViewController(HomeViewControler, animated: true)
print("You Are ready to login")
}

关于ios - 在 API 中创建 if 条件时,如何修复 swift 代码中调用 Storyboard 的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56304695/

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