简体   繁体   English

swift Eureka 在多个条件下隐藏行

[英]swift Eureka hiding row on multiple conditions

I am trying to hide an ActionSheetRow based on multiple conditions, I attempted to set an if statement but this did not work.我试图根据多个条件隐藏 ActionSheetRow,我试图设置一个 if 语句,但这不起作用。 I would like to know if anyone has tried or come across this?我想知道是否有人尝试过或遇到过这种情况?

<<< SwitchRow("switchRow"){
            $0.title = "The switch to hide the row when on"
        }
        <<< ActionSheetRow<String>("number") {
            $0.title = "How many sports will be played"
            $0.hidden = $0.hidden = Condition.function(["switchRow"], { form in
                return ((form.rowBy(tag: "switchRow") as? SwitchRow)?.value ?? false)
            })
            $0.selectorTitle = "How many sports will be played"
            while i <= places.count{

                choices.append("\(i)")

                i += 1

         }
            $0.options = choices
    }
        <<< ActionSheetRow<String>("firstSport"){
            $0.hidden = Condition.function(["playSport"], { form in
                return ((form.rowBy(tag: "playSport") as? SwitchRow)?.value ?? false)
            })
            $0.title = "Which is the first sport"
            $0.selectorTitle = "Which is the first sport?"
            $0.options = ["NBA", "MLB", "NFL",]
    }
<<< ActionSheetRow<String>("secondSport"){

        $0.title = "Which is the second sport"
        $0.selectorTitle = "Which is the second sport?"
        $0.options = ["NBA", "MLB", "NFL"]

        $0.hidden = Condition.function(["number"])
        { form in
            if let section = form.rowBy(tag: "number") as? ActionSheetRow<String> {
                if section.value == "1" {
                    return true
                }
            }
            return false
        }
    }

I would like the "secondSport" ActionSheetRow hidden if the switch is on or if the user picks 1 in the "number" ActionSheetRow.如果开关打开或用户在“数字”ActionSheetRow 中选择 1,我希望隐藏“secondSport”ActionSheetRow。 Is this something that is possible?这是可能的吗?

Thank you all feedback welcomed.谢谢大家的反馈欢迎。

It's probably too late for you, but I'll post here since I didn't find a proper answer elsewhere.对你来说可能为时已晚,但我会在这里发布,因为我没有在其他地方找到正确的答案。

You can use results from multiple rows in the input Dictionary to the Condition for hidden as follows:您可以将输入字典中多行的结果用于隐藏的条件,如下所示:

$0.hidden = .function(["SwitchRow1","SwitchRow2"], { form -> Bool in
                        let c1: Bool = ((form.rowBy(tag: "SwitchRow1") as? SwitchRow)?.value ?? false)
                        let c2: Bool = ((form.rowBy(tag: "SwitchRow2") as? SwitchRow)?.value ?? false)
                        let finalBool = c1 && c2
                        return (!finalBool)
                    })
                }

I have used SwitchRow as an example, but the Conditional should hold true if you want to use it for some other type of row.我以 SwitchRow 为例,但如果您想将它用于其他类型的行,则条件应该成立。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM