简体   繁体   中英

Hiding a row in Eureka depending if it contains a value or not

I made a form with Eureka and was wondering how to hide a row or section depending if it contains a value or not:

form
            +++ Section("Car")
            <<< TextRow() {
                $0.title = car?.name
            }
            +++ Section("Car color")
            <<< TextRow() {
                $0.title = car?.color
            }
            +++ Section("Car description")
            <<< TextRow() {
                $0.title = car?.description
                $0.cell.textLabel?.numberOfLines = 0
            }
            +++ Section("Car brand")
            <<< TextRow() {
                $0.title = car?.brandName
            }
          +++ Section("Comment")
            <<< TextRow() {
            $0.tag = "Comment"
               $0.title = car?.internComment
                $0.cell.textLabel?.numberOfLines = 0
                $0.hidden = Condition.function([])
                { form in
                    if (form.rowBy(tag: "Comment") as? TextRow) != nil {
                       return false
                    }
                    return true
                }
        }

I tried it with

$0.hidden = Condition.function([])
                { form in
                    if (form.rowBy(tag: "Comment") as? TextRow) != nil {
                       return false
                    }
                    return true
                }

but it is hiding it regardless if it contains a value or not.

You are checking for the row itself, check for its value

$0.hidden = Condition.function([]) { form in
   if (form.rowBy(tag: "Comment") as? TextRow)?.value != nil {
      return false
   }
   return true
}

or shorter

$0.hidden = Condition.function([]) { form in
    return !((form.rowBy(tag: "Comment") as? TextRow)?.value ?? false)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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