我是新手,很快,当输入了正确的电子邮件和密码并且迅速按下了登录按钮时,我试图切换到第二个场景。
到目前为止是我的代码:
class FirstScreen: UIViewController {
@IBOutlet weak var headerLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var emailLabel: UITextField!
@IBOutlet weak var passwordLabel: UITextField!
@IBAction func loginButton(_ sender: UIButton)
{
let emailLabel1 = emailLabel.text!
let passwordLabel1 = passwordLabel.text!
if((emailLabel1.contains("email")) && (passwordLabel1.contains("password")))
{
}
else
{
print("ERROR")
}
}
}
如何在if语句中以编程方式切换到第二个场景?我正在使用xCode 11和Swift 5.1。任何帮助将非常感谢
下面是更新的代码
class FirstScreen: UIViewController {
@IBOutlet weak var headerLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var emailLabel: UITextField!
@IBOutlet weak var passwordLabel: UITextField!
@IBAction func loginButton(_ sender: UIButton)
{
let emailLabel1 = emailLabel.text!
let passwordLabel1 = passwordLabel.text!
if((emailLabel1.contains("email")) && (passwordLabel1.contains("password")))
{
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let secondView = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
if #available(iOS 13.0, *) {
self.navigationController!.pushViewController(secondView, animated: false)
}else{
self.present(secondView, animated: true, completion: nil)
}
}
else
{
print("ERROR")
}
}
}