1

この単純なフォームで XLForm を使用しています。コードは Swift で書かれています。検証に問題があります。電子メールやその他のフィールドに XLForm の内部バリデーターを使用したいのですが、方法がわかりません。他のフィールドにデータが入力されているかどうかを確認するだけです。マニュアルは Obj-C で書かれており、Swift の例は見つかりませんでした。誰かがそれを実装する方法のヒントを教えてくれますか? userEmail.required = true で試していましたが、うまくいきません。フォームを送信する前にフィールドを検証するために、saveTapped メソッドに実装するメソッドを探していましたが、解決策を見つけることができませんでした。

class FormViewController: XLFormViewController {


required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder);
    self.setupForm()
}

override func viewDidLoad() {
    super.viewDidLoad()
}
@IBAction func saveTapped(sender: AnyObject) {


            println(form.formRowWithTag("userEmail").value as? String)
            println(form.formRowWithTag("userPassword").value as? String)
            println(form.formRowWithTag("userName").value as? String)

}

private func setupForm() {

    let form = XLFormDescriptor(title: "Registration")

    // Section 1
    let section1 = XLFormSectionDescriptor.formSection() as XLFormSectionDescriptor
    form.addFormSection(section1)

    let userEmail = XLFormRowDescriptor(tag: "userEmail", rowType: XLFormRowDescriptorTypeText, title: "Email")
    userEmail.required = true
    section1.addFormRow(userEmail)

    let userPassword = XLFormRowDescriptor(tag: "userPassword", rowType: XLFormRowDescriptorTypePassword, title: "Password")
    userPassword.required = true
    section1.addFormRow(userPassword)


    let userName = XLFormRowDescriptor(tag: "userName", rowType: XLFormRowDescriptorTypePassword, title: "First name")
    userName.required = true
    section1.addFormRow(userName)


    self.form = form
}

}

4

1 に答える 1