Swift - 使用 Eureka 获取 textField 表单的值

Swift - Get value of textField form with Eureka

我正在做一个 Eureka 表单的应用程序,问题是我不知道如何获取第一个 textField 的值。

问题是我应该得到第一部分 DecimalRow 的值,我应该将它与第二部分 KalkulationCell(这是一个自定义单元格)的 textField 相乘,但我不知道如何合并这些部分.

import UIKit
import Eureka

class ViewController: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //var rules = RuleSet<String>()

        form +++ Section("EINGABESUMME BRUTTO (EXXL MWST)")

        {[=11=].header?.height = { 20 }}
            <<< DecimalRow(){
                [=11=].title = " "
              //[=11=].value = 54
                [=11=].tag = "MyRowTag"

        }

            .cellUpdate { cell, row in
                    cell.textField?.font = .boldSystemFont(ofSize: 18.0)

        }



        let row: DecimalRow? = form.rowBy(tag: "MyRowTag")
        let value = row?.value

        // Get the value of all rows which have a Tag assigned
        // The dictionary contains the 'rowTag':value pairs.
        let valuesDictionary = form.values()
        print(valuesDictionary)




        form +++ Section("ZIEL-DB PROJEKT BRUTTO")
        {
            [=11=].header?.height = { 20 }

            }

            <<< KalkulationRow {
              row in
       row.cell.valueField.text = "54.00"

                row.tag="hello"
         }




        form +++ Section("RABATT")
        {
            [=11=].header?.height = { 20 }

            }
            <<< KalkulationRow { row in
                 row.cell.valueField.text = "54.00"

        }


        form +++ Section("SKONTO")
        {
            [=11=].header?.height = { 20 }

            }

            <<< IntRow(){
                [=11=].title = "Tage:"
                [=11=].placeholder = "2"
                [=11=].add(rule: RuleRequired())

                }
                .cellUpdate { cell, row in

                    cell.textField?.font = .boldSystemFont(ofSize: 18.0)
            }
            <<< KalkulationRow { row in
                 row.cell.valueField.text = "54.00"
        }
        form +++ Section("DIVERSE ABZUGE")
        {
            [=11=].header?.height = { 20 }

            }
            <<< KalkulationRow { row in
                row.cell.valueField.text = "54.00"
        }



        form +++ Section("EINGABESSUME NETTO")
        {
            [=11=].header?.height = { 20 }

            }
            <<< DecimalRow(){
                [=11=].title = " "
                [=11=].value = 54.00
                [=11=].placeholderColor = UIColor.green


                }
                .cellUpdate { cell, row in
                    cell.textField?.font = .boldSystemFont(ofSize: 18.0)
                    cell.textField?.textColor = UIColor.green
                    cell.textField?.isUserInteractionEnabled = false
        }


        form +++ Section("ZIEL-DB PROJEKT NETTO")
        {
            [=11=].header?.height = { 20 }

            }

            <<< KalkulationRow { row in
                 row.cell.valueField.text = "54.00"
        }


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


}

正如 vadian 所建议的,您可以使用 onChange 方法检测文本更改,如下所示:

.onChange({ decimal in

     print(decimal)
})

最终代码为:

{
        [=11=].header?.height = { 20 }

        }
        <<< DecimalRow(){
            [=11=].title = " "
            [=11=].tag = "MyRowTag"

            }
            .onChange({ decimal in

                print(decimal)
            })
            .cellUpdate { cell, row in
                cell.textField?.font = .boldSystemFont(ofSize: 18.0)
}