[英]MultipleSelectorRow in Eureka forms (Swift) how to Cast FormValues to String array?
[英]How to sort MultipleSelectorRow values in Eureka library in Swift?
我的用例描述了一個字段的必要性,在該字段中用戶可以選擇從A到F的多個階段。為了實現這一點,我使用了MultipleSelectorRow和Eureka庫:
<<< MultipleSelectorRow<String>("phase") {
$0.title = "Phase"
$0.options = ["A", "B", "C", "D", "E", "F"]
}
當用戶選擇任何選項時,我希望值以字母順序“A,B,C ...”顯示所選選項,會發生的是文本總是以隨機順序顯示,我試過通過擴展代碼來實現字母順序:
<<< MultipleSelectorRow<String>("phase") {
$0.title = "Phase"
$0.options = ["A", "B", "C", "D", "E", "F"]
}.onChange { row in
row.value = Set(row.value!.sort())
}
正確計算表達式,但我仍然無法按字母順序獲取值。
在發布問題時,我意識到,當Eureka使用Set來存儲字段時,它將永遠不會被排序。
在這種情況下,我已經更改了cellUpdate方法,以使用如下所述的排序值更新detailTextLabel:
<<< MultipleSelectorRow<String>("phase") {
$0.title = "Phase"
$0.options = ["A", "B", "C", "D", "E", "F"]
}.cellUpdate { cell, row in
if (row.value != nil) {
cell.detailTextLabel?.text = row.value!.sort().joinWithSeparator(", ")
}
}
我還提議在Eureka庫上修復默認情況下按字母順序排序。 有關https://github.com/xmartlabs/Eureka/pull/474的更多詳細信息
更新此問題已在Eureka 1.7.0(2016.07.07)修訂並發布
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.