【发布时间】:2017-03-14 17:00:54
【问题描述】:
我正在尝试在 Swift 2 中创建一个必填字段。每次运行此代码时,我都没有收到任何错误,但我从未收到文本字段为空的错误消息。 segue 总是被执行。知道我做错了什么吗?
谢谢!
@IBOutlet weak var userName: UITextField!
@IBAction func userConfermation(sender: AnyObject) {
if userName.text!.isEmpty {
let alertController = UIAlertController(title: "Error",
message: "Incorrect Password", preferredStyle:UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss",
style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
} else {
performSegueWithIdentifier("final", sender: self)
}
return
}
【问题讨论】:
-
使用调试器逐步完成。
-
很明显,
userName.text中有一些文字。
标签: ios swift string uitextfield