ios - Swift iOS 8 中的导航验证

标签 ios xcode swift ios8 xcode6

This is a simple project which showing the navigation from one controller to another.

This picture shows that after I've pressed sign in without filling in the text field, it still redirects to next controller with alert message

我已经验证了如果两个文本字段都为空则用户无法登录。但是,警报消息会弹出,但它仍会导航到下一个 Controller 。如何克服这个问题?这存在于两个文本字段都是空白并且只显示警报消息,而不是导航到下一个 Controller 时?

最佳答案

我假设您有一个从“登录”按钮到下一个场景的转场。所以你要做的是实现

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

然后检查标识符是否等于来自登录按钮的 segue 标识符。

我会将您的验证移动到此方法中,如果验证失败则返回 false,否则返回 true。

关于ios - Swift iOS 8 中的导航验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29478481/

相关文章:

ios - RxSwift - 将序列拆分成更小的序列以连接

ios - 卡里斯塔 OBD ||与 iOS 设备的设备通信

ios - UIView自动布局滑入屏幕或滑出屏幕动画

ios - NSCFCalendar dateFromComponents : components cannot be nil

ios - Xcode Beta 6 上的 NSString 和 String

ios - Swift 5 加载多个 AVAudioPlayer 导致打开文件过多错误

ios - 强制 collectionView 只有 2 行

ios - 带有 TextField 的 SwiftUI 列表在键盘出现/消失时进行调整

swift - 在代码中更改 Storyboard "View As"设备

ios - 为什么应用程序在 itunes API 中找不到歌曲时会崩溃?