我有两个pickerView,即pickerView1 = car_make
,pickerView2 = car_model
。
如果我选择car_make = Kia
,我希望pickerView2显示模型数组[Rio, Venga, Ceed]
,如果我从pickerView1中选择了car_make=Ford
,那么我希望pickerView2显示模型数组{{ 1}}。
我已经尝试编辑[Mondeo, Ka, Focus]
函数,并且已经完成管理
didSelectRow
但是我不知道如何将新数组分配给carModelPicker
答案 0 :(得分:2)
您需要
struct Car {
let name:String
let models:[String]
}
然后像这样填充数组
cars = [Car(name: "ppp", models: ["1","2","3"])]
对于picker1
的数字行为cars.count
,对于picker2
的数字行为cars[selected].models.count
哪里
var selected = 0 // suppose you will show models of first car initially
当用户点击didSelect
时
if pickerView == picker1 {
selected = row
picker2.reloadAllComponents()
}