0

我有两个pickerViews pickerView1 = car_make,即pickerView2 = car_model

如果我选择car_make = Kia,我希望pickerView2 显示模型数组[Rio, Venga, Ceed],如果我car_make=Ford从pickerView1 中选择,那么我希望pickerView2 显示模型数组[Mondeo, Ka, Focus]

我已经尝试编辑该didSelectRow功能,并已管理

if pickerView == carMakePicker {
    if carMake[row] == "Kia"{
        // How to assign new array?
    }
}

但后来我不知道如何将新数组分配给 carModelPicker

4

1 回答 1

2

你需要

struct Car {
    let name:String
    let models:[String]
}

然后像这样填充数组

cars = [Car(name: "ppp", models: ["1","2","3"])]

对于picker1becars.count和 for picker2be的行数cars[selected].models.count

在哪里

var selected = 0 // suppose you will show models of first car initially 

当用户点击didSelect

if pickerView == picker1 {
   selected = row
   picker2.reloadAllComponents()  
}
于 2019-07-17T13:57:30.143 回答