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

时间:2018-07-11 08:56:01

标签: swift eureka-forms

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

问题是我应该获取第一部分DecimalRow的值,并且应该将其与第二部分KalkulationCell(这是一个自定义单元格)的textField相乘,而我不知道如何合并这些部分。 / p>

import UIKit
import Eureka

class ViewController: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //var rules = RuleSet<String>()

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

        {$0.header?.height = { 20 }}
            <<< DecimalRow(){
                $0.title = " "
              //$0.value = 54
                $0.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")
        {
            $0.header?.height = { 20 }

            }

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

                row.tag="hello"
         }




        form +++ Section("RABATT")
        {
            $0.header?.height = { 20 }

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

        }


        form +++ Section("SKONTO")
        {
            $0.header?.height = { 20 }

            }

            <<< IntRow(){
                $0.title = "Tage:"
                $0.placeholder = "2"
                $0.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")
        {
            $0.header?.height = { 20 }

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



        form +++ Section("EINGABESSUME NETTO")
        {
            $0.header?.height = { 20 }

            }
            <<< DecimalRow(){
                $0.title = " "
                $0.value = 54.00
                $0.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")
        {
            $0.header?.height = { 20 }

            }

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


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


}

1 个答案:

答案 0 :(得分:1)

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

.onChange({ decimal in

     print(decimal)
})

最终代码将是:

{
        $0.header?.height = { 20 }

        }
        <<< DecimalRow(){
            $0.title = " "
            $0.tag = "MyRowTag"

            }
            .onChange({ decimal in

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