gpt4 book ai didi

swift - 如何在 swift 中使用 ID 进行简单登录

转载 作者:行者123 更新时间:2023-11-28 15:57:09 25 4
gpt4 key购买 nike

我想使用简单的验证在 Swift 中创建登录函数,但这行不通。我应该怎么办?当我在文本字段中输入 123456 然后单击登录按钮时,应该会转到下一页:

   @IBOutlet weak var IDtext: UITextField!

var ID = self.IDtext.text

@IBAction func LogButton(_ sender: Any) {

If( ID == "123456" )
{
dispatch_async(dispatch_get_main_queue(),
{
() -> Void in let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Home") as! UIViewController
self.presentViewController(viewController, animated: true, completion: nil)
}

}
else
{
var alert = UIAlertView(title: "Invalid", message: "Invalid ID", delegate: self, cancelButtonTitle: "OK")
alert.show()
}
}

谢谢!

最佳答案

@IBAction func LogButton(_ sender: Any) {

  var ID = self.IDtext.text 
if ID = "123456" {
let pushVC:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Home") as! UIViewController
self.navigationController?.pushViewController(pushVC, animated: true)
} else {
var alert = UIAlertView(title: "Invalid", message: "Invalid ID", delegate: self, cancelButtonTitle: "OK")
alert.show()
}
}

此外,如果您的家庭类(class)的名称是 Something say "HomeVC",则按如下方式替换您的行:-

let pushVC:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Home") as! HomeVC

关于swift - 如何在 swift 中使用 ID 进行简单登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41547306/

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