I'm trying to update values of each LabelRow in my SplitRow every time VC appears one the screen (it has to be like that). I've tried using .cellUpdate on both LabelRows but it just crashes. When I use .updateCell on just one of LabelRows, it updates value of that row just fine. Is there a way to update both of them at the same time? I tried to use .updateCell on SplitRow but then I can't update values (they are read-only?). The failing code part:
<<< SplitRow<LabelRow, LabelRow>() {
$0.rowLeftPercentage = 0.5
$0.rowLeft = LabelRow() {
$0.title = "Expected"
$0.tag = "temp_expected"
} //tried callbacks here
$0.rowRight = LabelRow() {
$0.title = "Last"
$0.tag = "temp_last"
} //tried callbacks
} //also tried there but cant update values
EDIT: here's what I've tried
<<< SplitRow<LabelRow, LabelRow>() {
$0.rowLeftPercentage = 0.5
$0.rowLeft = LabelRow() {
$0.title = "Expected"
$0.tag = "temp_expected"
}.cellUpdate {
$1.value = "value1" //here would go value from other object, doesn't work either
}
$0.rowRight = LabelRow() {
$0.title = "Last"
$0.tag = "temp_last"
} .cellUpdate {
$1.value = "value2" // same as above
}
}
And other one
<<< SplitRow<LabelRow, LabelRow>() {
$0.rowLeftPercentage = 0.5
$0.rowLeft = LabelRow() {
$0.title = "Expected"
$0.tag = "temp_expected"
}
$0.rowRight = LabelRow() {
$0.title = "Last"
$0.tag = "temp_last"
}
}.cellUpdate {
$1.value?.left = "value1" //does nothing
$1.value?.right = "value2" //does nothing
}
Your code crashes because of a stack overflow. The setter of
$1.valuecallscell.update(), which callscellUpdate, which forms an infinite loop :(I've found this dirty trick that kind of works:
Wrap the
row.value = ...line in aDispatchQueue.main.asynccall:In reality though, you should find another place to set your row's value. It sounds like the value changes over time and you want to always show the latest value. Try using a Reactive approach using RxSwift. You'd subscribe to an
Observable<String>, and set each value you receive to the row's value.