UIPickerView - 如何使某些行不可选择并变灰
我正在为日期创建自己的 UIPickerview,因为我只需要月和日,不需要年,所以我无法使用 UIDatePicker。当选择不同的月份时,我似乎无法复制 UIDatepicker 灰色的不可用日期的方式。 例如:选择 11 月时,可以选择 1-30 天,但使用 UIDatepicker 时则不能选择 31 天。有谁知道如何复制此并使某些行变灰且不可选择。 提前致谢
I am creating my own UIPickerview for dates as I need only Months and Days and do not want years, so I cannot use UIDatePicker. When different months are selected I cannot seem to replicate the way UIDatepicker gray's out the unavailable days.
For example: when November is selected days 1-30 are selectable but 31 is not when using the UIDatepicker. Does anyone know how to replicate this and make certain row grayed out and unselectable.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道您可能已经弄清楚了这一点,但我想为那些寻求相同答案的人添加一些进一步的信息。
您可以尝试的另一种途径是通过:
在该方法中,您将检查 pickerView 中的特定组件是否具有有效的选择。如果没有,则将特定组件(列 - 为什么他们不直接这样称呼它)重置为有效行:
这将产生这样的效果:如果用户选择特定的无效行,它将向上滚动(或向下)到一个有效的。
此外,您可以更改相关组件的数据集,然后执行以下操作:
请记住,当您设置选取器时,您必须在第一次运行时进行此验证,因此确保数据集中没有无效数据集默认情况下选择器视图。
I realize you may have already figured this out, but I wanted to add some further information for those looking for the same answer.
An alternative route that you might try is via:
In that method, you would check to see whether or not the particular components in the pickerView had a valid selection. If it didn't then reset the particular component (column - why didn't they just call it that) to a valid row with:
This will give the effect that if the user chooses a particular invalid row, it will scroll back up (or down) to a valid one.
Additionally, you could change the dataset for the component in question and then do a:
Just keep in mind that when you set up the picker, you'll have to do this validation on the first run so ensure that no invalid datasets are in the pickerView by default.
您将必须编写自定义选择器视图
You are going to have to write a custom picker view