首页 > 解决方案 > 在选取器视图中显示字符串数组?

问题描述

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

标签: iosswiftuipickerview

解决方案


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 委托函数。你不需要那个来显示数据


推荐阅读