swift - Swift - If 语句不会运行
问题描述
我的if
声明不会运行。我不知道为什么它不会运行。
@IBOutlet weak var Email: UITextField!
@IBOutlet weak var Password: UITextField!
@IBAction func Login(_ sender: AnyObject) {
let email = Email.text
let password = Password.text
let postURL = URL(string: "https://www.example.com/app/signin.php?email" + email! + "&password" + password!)!
var postRequest = URLRequest(url: postURL)
postRequest.httpMethod = "POST"
postRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
postRequest.setValue("application/json", forHTTPHeaderField: "Accept")
let httpBODY = postRequest.httpBody
let mail : Data = email!.data(using: .utf8)!
if httpBODY == mail { // Error is happening right here
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "LoggedOn")
self.navigationController?.pushViewController(vc, animated: true)
} else {
let title = "Wrong!"
let message = "Incorrect username or bad Password."
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default)
alertController.addAction(OKAction)
var alertWindow : UIWindow!
alertWindow = UIWindow.init(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController.init()
alertWindow.windowLevel = UIWindowLevelAlert + 1
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alertController, animated: true)
}
}
预期:Button 将获取电子邮件和密码并向 url 发送请求。如果电子邮件和密码有效,它将显示电子邮件。如果电子邮件等于 HTTP 正文,那么它将重定向到 LoggedOn Storyboard。
发生了什么: Button 将获取电子邮件和密码并向 url 发送请求。如果电子邮件和密码有效,它将显示电子邮件。如果电子邮件等于 HTTP 正文,则它什么也不做。
Storyboard 未连接到 LoggedOn Storyboard。我不知道它是否需要。有人可以帮我弄清楚发生了什么吗?
解决方案
推荐阅读
- python - 试图通过 gspread 在 Google 表格中找到最高的空单元格
- sql - 为什么我的 SELECT 语句在 SELECT MAX(ID) 时返回 2 行?
- machine-learning - 是否可以逐步训练 sklearn 模型(例如 SVM)?
- python - SQL 查询列不存在
- php - 如何在laravel 5中存储excel表格中的图像
- c# - 如何让 C# WPF MVVM 屏幕保护程序使用双显示器?
- mysql - 我想从 table1 操作“AS 年龄”列
- ruby - 旧宝石是否总是适用于更高版本的 ruby?
- laravel - Laravel:hasMany 关系使用 where 子句中断查询
- c# - 如何让 Parent 只使用它的游戏对象而不被子类访问?