使用另一个数组调用字典键

Calling dictionary keys using another array

我有一个 UIPickerView 显示来自 Array 个键的数据。

var pokemonData = ["Nidoran", "Clefairy", "Spearow", "Ivysaur", "Gengar", "Arcanine", "Gyarados", "Onix", "Pikachu", "Vaporeon"]

我也有这个 Dictionary,但我想在选择器上选择某项时调用它显示在标签中的每个键。

var typeData = [

    "Nidoran" : "Type: Poison",
    "Clefairy" : "Type: Normal",
    "Spearow" : "Type: Normal, Flying",
    "Ivysaur" : "Type: Grass, Poison",
    "Gengar" : "Type: Ghost, Poison",
    "Arcanine" : "Type: Fire",
    "Gyarados" : "Type: Water, Flying",
    "Onix" : "Type: Rock, Ground",
    "Pikachu" : "Type: Electric",
    "Vaporeon" : "Type: Water"

]

我该怎么做?我使用这个选择器功能来更改标签

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    pokeLabel.text = pokemonData[row]

}

我的第二个标签是...

@IBOutlet weak var typeLabel: UILabel!

只需使用该类型数据 Dictionary 获取所选键的值。

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
     pokeLabel.text = pokemonData[row]
     typeLabel.text = typeData[pokemonData[row]]
}