swift - 无法使用类型为 'validate' 的参数列表调用 '(delegate:viewController)'

标签 swift cocoa-touch

我正在尝试使用名为 SwiftValidator 的 pod。

我已尝试按照 GitHub 页面中的说明进行操作,但我不知道如何修复以下错误:

Cannot invoke 'validate' with an argument list of type '(delegate:viewController)'

在这里你可以找到框架: https://github.com/jpotts18/SwiftValidator

编辑:

这是我的代码

override func viewDidLoad() {
    super.viewDidLoad()

    //Validation
    validator.registerField(tfName, rules: [RequiredRule(), FullNameRule()])
}

@IBAction func btnValidatePressed(sender: AnyObject) {
        validator.validate(delegate:self) //Error Line
    }

//MARK: - Validation

func validationSuccessful() {

}

func validationFailed(errors:[UITextField:ValidationError]) {
    // turn the fields to red
    for (field, error) in validator.errors {
        field.layer.borderColor = UIColor.redColor().CGColor
        field.layer.borderWidth = 1.0
        error.errorLabel?.text = error.errorMessage // works if you added labels
        error.errorLabel?.hidden = false
    }
}

最佳答案

错误的原因是您没有实现必要的委托(delegate)。您尝试进行验证的 View Controller 应如下所示:

class YourViewController: UIViewController, ValidationDelegate {
   (..)
}

关于swift - 无法使用类型为 'validate' 的参数列表调用 '(delegate:viewController)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31240976/

相关文章:

iphone - 简单协议(protocol)示例的 ARC 语义问题?

ios - TableView 滚动问题与内容偏移

iOS swift : AWS SDK - downloading file from S3 - get contents without saving file

ios - Xcode 9 Swift 4 UITableView 无法识别的选择器发送到实例

ios - 在 webview 中创建唯一标识符

iphone 设备方向

objective-c - 如何将文本从 iOS 应用程序导出到台式电脑?

ios - UIScrollView:在 scrollViewDidScroll 中获得更好的 contentOffset 预测:

ios - UITableViewCell 中的圆形图像

Swift:线程 1:信号 SIGABRT