简体   繁体   中英

Navigation Validation in Swift iOS 8

这是一个简单的项目,显示了从一个控制器到另一个控制器的导航。

此图显示了我在未填写文本字段的情况下按下登录后,它仍然重定向到带有警告消息的下一个控制器

I've made a validation that a user can't login if both text field is blank. However, the alert message is popped out but it still will navigate to the next controller. How to overcome this problem? This exists while both text field is blank and just only showing the alert message, not navigating to next controller?

I'm assuming you have a segue from the Login button to the next scene. So what you'll want to do is implement

override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool 

then check if the identifier is equal to the segue identifier from the Login button.

I would move your validation into this method and return false if the validation fails, otherwise true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM