【问题标题】:How can I set UIPickerView at other than the default index?如何将 UIPickerView 设置为默认索引以外的位置?
【发布时间】:2011-02-15 13:10:31
【问题描述】:

我有一个值为 5 的整数,我想用这个索引启动我的 UIPickerView,现在我该怎么办? 通常 UIPickerView 在默认的 0 索引行上,但我希望它在用户定义的索引上,可以是 5、6 或任何其他数字。

【问题讨论】:

    标签: ios uipickerview


    【解决方案1】:

    假设您的选择器在属性“myPicker”中被引用,那么在 viewDidLoad 中,执行:

    [self.myPicker selectRow:rowInt inComponent:componentInt animated:NO]
    

    【讨论】:

    • rowInt 和 componentInt 是什么?
    • 它们是整数,表示您要预先选择哪个组件的哪一行。
    • inComponent 是什么意思?
    • 一个选择器可以有多个“轮子”。默认的日期选择器就是一个很好的例子——它有日期、小时、分钟等单独的微调器部分(取决于你如何配置它)。在 Cocoa-Touch-ese 中,这些是“组件”。
    • 如果我想从选择器视图中选择第一个项目应该传入参数
    【解决方案2】:

    Swift 4.2 更新

    在 UIPickerView 中设置默认行,

      myPicker.selectRow(5, inComponent: 0, animated: true)
    

    其中 myPicker 是 UIPickerView 的名称,5 是所需行的索引。

    【讨论】:

      猜你喜欢
      • 2012-07-31
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多