情况:
我想做什么:
代码:
import UIKit
import Eureka
struct ComboType : Equatable {
let nume : String
let id : Int
}
class clsModel_form_continente{
var v_combo: [ComboType] = []
var continent_lista_selectat: ComboType!
init(_ v_combo: [ComboType]){
self.v_combo = v_combo
}
}
class pagina_lista: FormViewController {
var model_formular1: clsModel_form_continente!
var combo_selectata: ComboType!
var v_combo: [ComboType]!
override func viewDidLoad() {
super.viewDidLoad()
v_combo = [ComboType(nume: "Any", id: 0), ComboType(nume: "Antarctica", id: 10), ComboType(nume: "Africa", id: 50), ComboType(nume: "Asia", id: 75)]
combo_selectata = ComboType(nume: "Any", id: 0)
model_formular1 = clsModel_form_continente(v_combo); model_formular1.continent_lista_selectat = combo_selectata
create_form2()
//default selected value in my list
let defaultContinent = combo_selectata
if let row = self.form.rowBy(tag: (defaultContinent?.nume)!) as? ListCheckRow<ComboType> {
row.selectableValue = defaultContinent
row.didSelect()
}
}
func create_form2(){
form +++ SelectableSection<ListCheckRow<ComboType>>("Continents", selectionType: .singleSelection(enableDeselection: false)) // **here I want to use .multipleSelection**
{section in
section.tag = "ID_LISTA"
}
for element in v_combo {
form.last! <<< ListCheckRow<ComboType>(){ listRow in
if element.id == 0 //i make first row green
{
listRow.cell.backgroundColor = UIColor.green
}
listRow.title = element.nume
listRow.selectableValue = element
listRow.value = element
listRow.tag = element.nume
listRow.onChange{[unowned self] row in
if let valoare = row.value{
self.combo_selectata = valoare
self.model_formular1.continent_lista_selectat = valoare
}
}
}
}
form.last! <<< ButtonRow("Button1") {row in
row.title = "Get List Value"
row.onCellSelection{[unowned self] cell, row in // clik on button
if let section = self.form.sectionBy(tag: "ID_LISTA") as?
SelectableSection<ListCheckRow<ComboType>> {
//read data from my list
if let valoare_form = section.selectedRow()?.value {
print("From my form .... Name: ",valoare_form.nume, " Id: ",valoare_form.id)
}else{
print( "Nothing is selected")
}
//read data from my object
print("From my Object ....... Name = ",self.model_formular1.continent_lista_selectat.nume," , Id = ", self.model_formular1.continent_lista_selectat.id)
print("\n")
}
}
}
}
}