[英]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.