[英]Swift Eureka SplitRow values updating
每次 VC 出现在屏幕上时,我都会尝试更新 SplitRow 中每个 LabelRow 的值(必须是这样)。 我在两个 LabelRows 上都尝试过 using.cellUpdate ,但它只是崩溃了。 当我只在其中一个 LabelRows 上使用 .updateCell 时,它会很好地更新该行的值。 有没有办法同时更新它们? 我尝试在 SplitRow 上使用 .updateCell 但我无法更新值(它们是只读的?)。 失败的代码部分:
<<< 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
编辑:这是我尝试过的
<<< 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
}
}
还有一个
<<< 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
}
您的代码由于堆栈溢出而崩溃。 $1.value
的设置器调用cell.update()
,它调用cellUpdate
,其中 forms 是一个无限循环:(
我发现这种肮脏的把戏很管用:
将row.value =...
行包装在DispatchQueue.main.async
调用中:
SplitRow<LabelRow, LabelRow>() {
$0.rowLeftPercentage = 0.5
$0.rowLeft = LabelRow() {
$0.title = "A"
$0.tag = "temp_expected"
}.cellUpdate { cell, row in
DispatchQueue.main.async {
row.value = ...
}
}
$0.rowRight = LabelRow() {
$0.title = "B"
$0.tag = "temp_last"
} .cellUpdate { cell, row in
DispatchQueue.main.async {
row.value = ...
}
}
}
但实际上,您应该找到另一个位置来设置行的值。 听起来值会随着时间而变化,并且您希望始终显示最新值。 尝试使用RxSwift使用 Reactive 方法。 您将订阅Observable<String>
,并将收到的每个值设置为该行的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.