Eureka表单 - 使用变量创建.hidden谓词

时间:2017-05-21 05:48:42

标签: swift eureka-forms

我试图在 Eureka 中创建一对 分段行 ,第二行取决于所选的单元格第一个。

我已经设法通过构建隐藏的行"文档中的示例 - 并通过硬编码我的值。 这是行规范的样子:

import UIKit
import Eureka

class ViewController: FormViewController {
    override func viewDidLoad() {
    super.viewDidLoad()
    form +++ Section("")
        <<< SegmentedRow<String>("firstChoice"){
            $0.selectorTitle = "firstChoice"
            $0.options = ["One","Two","Three"]
            $0.value = "One"
        }
        <<< SegmentedRow<String>("One"){ 
            $0.hidden = "$firstChoice != 'One'" //Row is hidden unless first choice is "One"
            $0.selectorTitle = "One"
            $0.options = ["1-1","1-2","1-3"]
            $0.value = "1-1"
        }
        <<< SegmentedRow<String>("Two"){ 
            $0.hidden = "$firstChoice != 'Two'" //Row is hidden unless first choice is "Two"
            $0.selectorTitle = "Two"
            $0.options = ["2-1","2-2","2-3"]
            $0.value = "2-1"
        }
        <<< SegmentedRow<String>("Three"){ 
            $0.hidden = "$firstChoice != 'Three'" //Row is hidden unless first choice is "Three"
            $0.selectorTitle = "Three"
            $0.options = ["3-1","3-2","3-3"]
            $0.value = "3-1"
        }
    }
}

但是,我真的希望能够通过Arrays指定值,所以我可以动态地更改它们。在为.hidden属性构建谓词函数时遇到了一个问题。 我想这样做:

import UIKit
import Eureka

let ChoiceOne = ["One", "Two", "Three"]
let ChoiceTwo = [["1-1","1-2","1-3"],["2-1","2-2","2-3"],["3-1","3-2","3-3"]]

class ViewController: FormViewController {
    override func viewDidLoad() {
    super.viewDidLoad()
    form +++ Section("")
        <<< SegmentedRow<String>("firstChoice"){
            $0.selectorTitle = "firstChoice"
            $0.options = ChoiceOne
            $0.value = ChoiceOne[0]
        }
        <<< SegmentedRow<String>("One"){
            $0.hidden = "$firstChoice != ChoiceOne[0]" //Row is hidden unless first choice is "One"
            $0.selectorTitle = ChoiceOne[0]
            $0.options = ChoiceTwo[0]
            $0.value = ChoiceTwo[0][0]
        }
        <<< SegmentedRow<String>("Two"){
            $0.hidden = "$firstChoice != ChoiceOne[1]" //Row is hidden unless first choice is "One"
            $0.selectorTitle = ChoiceOne[1]
            $0.options = ChoiceTwo[1]
            $0.value = ChoiceTwo[1][0]
        }
        <<< SegmentedRow<String>("Three"){
            $0.hidden = "$firstChoice != ChoiceOne[2]" //Row is hidden unless first choice is "One"
            $0.selectorTitle = ChoiceOne[2]
            $0.options = ChoiceTwo[2]
            $0.value = ChoiceTwo[2][0]
        }
    }
}

这构建正常,但在运行时我收到以下错误:

2017-05-21 07:41:27.547 EurekaTest[74681:12894860] *** NSForwarding: warning: object 0x7fa248e15f50 of class '_TtGC6Eureka12SegmentedRowSS_' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[_TtGC6Eureka12SegmentedRowSS_ valueForKey:]

我假设ChoiceOne[0]没有正确地作为字符串传递给谓词构建器,但我不太了解swift和这个构造以找出捷径。

此外,我希望能够在之后循环数组的大小以构造可变大小的segmentedRow。

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

您可以使用functions隐藏部分。

    $0.hidden = .function(["firstChoice"], { form -> Bool in
                    let row: RowOf<String>! = form.rowBy(tag: "firstChoice")
                    return row.value != self. ChoiceOne[0]
                })