【问题标题】:How to get current value of UIPickerView AFTER it has already been selected如何在 UIPickerView 被选中后获取当前值
【发布时间】:2021-06-01 16:53:00
【问题描述】:

称我为愚蠢,但我只是不知道如何在 UIPickerView 它已经被选中之后获取它的当前值。如果它刚刚通过使用委托的didSelectRowAt 方法进行了更改,那么有很多关于获取它的 SO Q&A,但是如果它已经设置了一段时间怎么办?你不能手动调用这个委托方法……可以吗?

我知道这可能很容易,但感谢您的帮助。

【问题讨论】:

    标签: swift uipickerview delegation


    【解决方案1】:

    UIPickerView 有一个 selectedRow 将返回当前选定的行:

    https://developer.apple.com/documentation/uikit/uipickerview/1614369-selectedrow

    let selected = myPicker.selectedRow(inComponent: 0) //gets the selection in the first component of the picker
    

    【讨论】:

    • 天哪,我怎么没看到。这是我的第一个假设,在寻找这样的方法时,我真的错过了它……连续两次。谢谢你。我会在 11 分钟内接受它,所以让我吧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 2019-05-24
    相关资源
    最近更新 更多