我正在在线上课程,我正在开发的应用基本上是Instagram的简化版本,如您所见,在左侧我有一个登录视图,在右侧我有一个签名视图向上。
相当简单直接,现在我Seque
从按钮的登录页面创建了一个按钮Register
,按下该按钮会将您带到注册视图(右侧的一个视图),这可以按预期工作,但是如果我在登录页面上并单击“登录”并且无论出于什么原因我都会显示错误消息,但是Seque
即使我从未按过,它也会立即执行注册画面register
这是我的故事板:
This is my code behind the Sign In
button located on the left view
@IBAction func btnSignIn(sender: AnyObject) {
if txtUsername.text == "" || txtPassword.text == "" {
displayAlert("Error", message: "Username and Password required!")
}
}
I have no other code inside this controller which would cause the Seque
to initialise.
If someone can shed some light into how I can stop this Seque
from happening on Sign In
click and only happen when I press Register
I'd appreciate it.
Update
经过进一步调查,这似乎与我正在显示的警报框有关。如果我注释掉警报框,然后按登录并让它出错但仍然不显示任何内容,请单击注册,将我带到右侧视图,单击登录并返回左侧以查看,然后按Sign In
显示警报框当它关闭时,似乎认为该视图控制器显示在页面上当前视图控制器之前的视图控制器中,这很奇怪。这是我的警报功能:
func displayAlert(title: String, message: String) { // Display alert message to user. Passing in title and message which will be displayed.
if #available(iOS 8.0, *) {
let a = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
a.addAction((UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
})))
self.presentViewController(a, animated: true, completion: nil)
} else {
// Fallback on earlier versions
}
}
您无需在操作中关闭警报视图控制器。当用户选择一个动作时,警报控制器将自动关闭。
由于您正在调用,因此dismissViewControllerAnimated
您将返回上一个视图控制器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句