【发布时间】:2017-12-04 18:45:48
【问题描述】:
我想做的是根据从选取器中选择的内容显示特定的文本字符串。例如,选择器中的蓝色、绿色和黄色选项可供选择。当您选择蓝色时,一些文本(例如,我爱海洋!)会输出到标签。
除了选择器中选择的内容之外,我无法更改任何其他内容的输出。
相关代码示例,
let colors = ["Blue", "Green", "Yellow"]
func numberOfComponents(in pickerView: UIPickerView) -> Int
{
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return colors[row]
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return colors.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
label.text = colors[row]
} //but I want this to return a text string when Blue is 'picked', another different string when Green is 'picked', and a third sting when Yellow is 'picked'
我已经设置好了,所以一旦在 pickerView 中进行了选择,数据就会出现在标签上,但是就像我说的那样,我只能从 pickerView 本身获取数据来显示。我希望根据您在选择器中的选择显示一些其他数据(您看不到)。
【问题讨论】:
-
didSelectRow委托方法的实现在哪里? -
我只是没有把它包括在这里...我现在把它放在帖子上..
标签: ios uipickerview uipickerviewcontroller uipickerviewdatasource