在选择器视图中显示字符串数组?

Show Array of String in Picker View?

如何在不使用 didSelect 委托方法的情况下在选择器视图中显示字符串数组?

func numberOfComponents(in pickerView: UIPickerView) -> Int
{
    return 1 // the amount of "columns" in the picker view
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
    return yourArray.count // the amount of elements (row)
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
    return yourArray[row] // the actual string to display for the row "row"
}

就这么简单。不需要 didSelect。每当您在选取器视图中更改选择时,都会调用 didSelect 委托函数。你不需要那个来显示数据