在Swift中获取UIPickerViewControl的选定值 [英] Getting selected value of a UIPickerViewControl in Swift

查看:128
本文介绍了在Swift中获取UIPickerViewControl的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Swift中获取UIPickerViewControl的选定值?

How can I get the selected value of a UIPickerViewControl in Swift?

我尝试过这样的事情:

labelTest.text = Spinner1.selectedRowInComponent(0).description

但这只返回选定的索引。我需要价值。

But this only returns the selected index. I need the value.

任何知道怎么做的人?

推荐答案

你必须将选择器视图委托设置为self并覆盖此功能

you will have to set the picker view delegate to self and override this function

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
   {
        // use the row to get the selected row from the picker view
        // using the row extract the value from your datasource (array[row])
    }

你可以根据你的用法使用它来提取

you can use this to extract as per your usage

var selectedValue = pickerViewContent[pickerView.selectedRowInComponent(0)]

其中pickerViewContent是你的dataSource数组

where pickerViewContent is your array of dataSource

这篇关于在Swift中获取UIPickerViewControl的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆