【问题标题】:How to hide a row / section based on selected value with Eureka framework如何使用 Eureka 框架根据所选值隐藏行/部分
【发布时间】:2016-01-31 16:25:38
【问题描述】:

我尝试使用Eureka framework 创建调查表。但是,如何隐藏特定选项选择的部分?

请帮忙!

let fruits = ["Apple", "Banana", "Coconut"]

form +++= SelectableSection<ImageCheckRow<String>, String>() { section in
    section.header = HeaderFooterView(title: "What is your favorite fruit ?")
}

for fruit in fruits {
    form.last! <<< ImageCheckRow<String>(fruit) { lrow in
        lrow.title = fruit
        lrow.selectableValue = fruit
    }
}

form +++ Section("xxxxxx Question") {
    //hide this section when apple is selected
    //$0.hidden =
}

form.last! <<< TextAreaRow() {
    $0.title = "Enter description here..."
}

【问题讨论】:

    标签: ios swift eureka-forms


    【解决方案1】:

    首先为您的水果部分设置一个标签,例如“fruits_section”。然后你可以像这样设置隐藏变量:

    $0.hidden = Condition.Function([]) 
                { form in
                    if let section = form.sectionByTag("fruits_section") as? SelectableSection<ImageCheckRow<String>, String> {
                        if section.selectedRow()?.title == "Apple" {
                            return true
                        }
                    }
                    return false
                }
    

    要在第一部分中选择一行时强制评估此隐藏条件,您可以使用第一部分的onSelectSelectableRow

    (section as! SelectableSection<ImageCheckRow<String>, String>).onSelectSelectableRow = { [weak self] _ in
         self?.form.sectionByTag("last_section_tag")?.evaluateHidden()
    }
    

    不要忘记为这两个部分设置正确的标签。

    如果您只有两个部分,您可以使用form.firstform.last 而不是使用标签,但不建议这样做。

    【讨论】:

    • 您好 Mathias Claassen,感谢您的回复。你能帮我解决另一个问题吗?谢谢。
    • 你写的第二段代码,它必须在Form里面的什么地方???
    猜你喜欢
    • 2020-10-21
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多