Reputation: 598
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:
Upvotes: 2
Views: 982
Reputation: 598
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"
}
}
Upvotes: 4
Reputation: 21
This my way to do it using an Json file and loop entries -->
do {
if let file = Bundle.main.url(forResource: "linhas_fretados", withExtension: "json") {
let data = try Data(contentsOf: file)
let json = JSON(data: data)
for (_,subJson):(String, JSON) in json {
let inserir_fretado = Linhas_Fretado(
linha: subJson["Linha"].stringValue,
hora_saida_sa: subJson["Campus Santo André Partida"].stringValue,
hora_saida_sbc: subJson["Campus São Bernardo Partida"].stringValue,
hora_saida_tmnl: subJson["Terminal Leste"].stringValue)
if(subJson["Campus Santo André Partida"] != ""){
self.Saida_SA.append(inserir_fretado)
}
if(subJson["Terminal Leste"] != ""){
self.Saida_TMNL.append(inserir_fretado)
}
if(subJson["Campus São Bernardo Partida"] != ""){
self.Saida_SBC.append(inserir_fretado)
}
}
} else {}
} catch {
print(error.localizedDescription)
}
let formulario = form
formulario +++ Section("Onde Voce está?:")
<<< SegmentedRow<String>("segments"){
$0.options = ["SA", "TERMINAL", "SBC"]
$0.value = "SA"
}
//#################### ONIBUS SAINDO DE SSANTOS ANDRE MANO #############
formulario +++ Section("Saindo de SA"){
$0.tag = "SA_s"
$0.hidden = "$segments != 'SA'"
}
var i = 0
while i <= (Saida_SA.count-1) {
form.sectionBy(tag: "SA_s")! <<< TextRow() { $0.title = "Linha \(self.Saida_SA[i].linha)" ; $0.value = self.Saida_SA[i].hora_saida_sa ; $0.disabled = true }
i = i + 1
}
//#################### ONIBUS SAINDO DO TERMINALLLLOUAOOOASOASOA #############
formulario +++ Section(){
$0.tag = "TERMINAL_s"
$0.hidden = "$segments != 'TERMINAL'"
}
var a = 0
while a <= (Saida_SA.count-1) {
form.sectionBy(tag: "TERMINAL_s")! <<< TextRow() { $0.title = "Linha \(self.Saida_TMNL[a].linha)" ; $0.value = self.Saida_TMNL[a].hora_saida_tmnl ; $0.disabled = true }
a = a + 1
}
//#################### ONIBUS SAINDO DE SAO BERNARDO DO CAMPO #############
formulario +++ Section(){
$0.tag = "SBC_s"
$0.hidden = "$segments != 'SBC'"
}
var i2 = 0
while i2 <= (Saida_SA.count-1) {
form.sectionBy(tag: "SBC_s")! <<< TextRow() { $0.title = "Linha \(self.Saida_SBC[i2].linha)" ; $0.value = self.Saida_SBC[i2].hora_saida_sbc ; $0.disabled = true }
i2 = i2 + 1
}
I lost a lot of time creating this and search around the internet, I does not find something else like this, so I hope you enjoy bro.
Upvotes: 0