在Picker View中显示字符串数组? [关闭]

问题描述 投票:-8回答:1

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

ios swift uipickerview
1个回答
-1
投票
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委托函数。您不需要那个用于显示数据

© www.soinside.com 2019 - 2024. All rights reserved.