Search code examples
swiftuitableviewfor-looprowseureka-forms

Eureka lib in swift: How can I loop rows?


Maybe it's a useless question, but I'm trying to make a "for loop" with labelRow, but it don't do what I want.

I want the same things as the example project of Eureka with SegmentedRow, but in segment I want to do a loop for rows.

Can someone guide me?

This is what I tried in view did load:

 self.form = Section()
        <<< SegmentedRow<String>("segments"){
            $0.options = ["Passées", "En cours", "Futures"]
            $0.value = "En cours"
        }
        
        +++ Section(){
            $0.tag = "past_s"
            $0.hidden = "$segments != 'Passées'" // .Predicate(NSPredicate(format: "$segments != 'Sport'"))
    }
    
    for it in self.past {
        self.form.last! <<< TextRow() { row in
            row.title = "Which is your favourite soccer player?"
        }
    }
    
    self.form +++= Section(){
        $0.tag = "waiting_s"
        $0.hidden = "$segments != 'En cours'"
    }
    
    for it in self.waiting {
        self.form.last! <<< TextRow() { row in
            row.title = "Which is your favourite soccer player?"
        }
    }
    
    self.form +++= Section(){
        $0.tag = "futur_s"
        $0.hidden = "$segments != 'Futures'"
    }
    
    for it in self.future {
        self.form.last! <<< TextRow() { row in
            row.title = "Which is your favourite soccer player?"
        }
    }

and thats what i'm waiting :)

self.form = Section()
    <<< SegmentedRow<String>("segments"){
        $0.options = ["Passées", "En cours", "Futures"]
        $0.value = "En cours"
    }
    
    +++ Section(){
        $0.tag = "past_s"
        $0.hidden = "$segments != 'Passées'" // .Predicate(NSPredicate(format: "$segments != 'Sport'"))
    }
    
    <<< LabelRow() { row in
        row.title = "1"
    }
    
    <<< LabelRow() { row in
        row.title = "temp"
    }
    
    +++ Section(){
        $0.tag = "waiting_s"
        $0.hidden = "$segments != 'En cours'"
    }
    
    <<< LabelRow() { row in
        row.title = "2"
    }
    
    <<< LabelRow() { row in
        row.title = "temp"
    }
    
    +++ Section(){
        $0.tag = "futur_s"
        $0.hidden = "$segments != 'Futures'"
    }
    
    <<< LabelRow() { row in
        row.title = "3"
    }
    
    <<< LabelRow() { row in
        row.title = "temp"
}
    

I've tried that too (and a lot of others ways):

form +++ Section()
form.last! <<< SegmentedRow<String>("segments"){
    $0.options = ["Passées", "En cours", "Futures"]
    $0.value = "En cours"
}

form +++= Section(){
    $0.tag = "past_s"
    $0.hidden = "$segments != 'Passées'"
}

for past in self.past {
    form.last! <<< LabelRow() { row in
        row.title = "1"
    }
}

and try this too :

form = Section()
    <<< SegmentedRow<String>("segments"){
        $0.options = ["Passées", "En cours", "Futures"]
        $0.value = "En cours"
}

form +++ self.pastSection!
form +++ self.waitingSection!
form +++ self.futurSection!

self.pastSection = Section("past_s") {
    $0.tag = "past_s"
    $0.hidden = "$segments != 'Passées'"
}

self.waitingSection = Section("waiting_s") {
    $0.tag = "waiting_s"
    $0.hidden = "$segments != 'En cours'"
}

self.futurSection = Section("futur_s") {
    $0.tag = "futur_s"
    $0.hidden = "$segments != 'Futures'"
}

for past in self.past {
    self.pastSection!
        <<< LabelRow() {
            $0.title = "test"
    }
}

for waiting in self.waiting {
    self.waitingSection!
        <<< LabelRow() {
            $0.title = "test"
    }
}

for futur in self.future {
    self.futurSection!
        <<< LabelRow() {
            $0.title = "test"
    }
}

form +++ self.pastSection!
form +++ self.waitingSection!
form +++ self.futurSection!

But I got an error like this:

photo of error


Solution

  • Finally I found the answer!

    form.delegate = nil
    form.removeAll()
    
    form +++= Section("DuplicateCounter") { row in row.tag = "DuplicateCounter" }
    
        <<< SegmentedRow<String>("segments"){
            $0.options = ["Passées", "En cours", "Futures"]
            $0.value = "En cours"
    }
    
    self.pastSection = Section("past_s") {
        $0.tag = "past_s"
        $0.hidden = "$segments != 'Passées'"
    }
    
    self.waitingSection = Section("waiting_s") {
        $0.tag = "waiting_s"
        $0.hidden = "$segments != 'En cours'"
    }
    
    self.futurSection = Section("futur_s") {
        $0.tag = "futur_s"
        $0.hidden = "$segments != 'Futures'"
    }
    
    form +++ self.pastSection!
    form +++ self.waitingSection!
    form +++ self.futurSection!
    
    for past in self.past {
        self.pastSection!
            <<< LabelRow("\(past.id)") {
                $0.title = "test"
        }
    }
    
    for waiting in self.waiting {
        self.waitingSection!
            <<< LabelRow("\(waiting.id)") {
                $0.title = "test"
        }
    }
    
    for futur in self.future {
        self.futurSection!
            <<< LabelRow("\(futur.id)") {
                $0.title = "test"
        }
    }