UIPickerView - 如何使某些行不可选择并变灰

发布于 2024-09-29 10:09:58 字数 193 浏览 7 评论 0原文

我正在为日期创建自己的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆光飞翔i 2024-10-06 10:09:58

我知道您可能已经弄清楚了这一点,但我想为那些寻求相同答案的人添加一些进一步的信息。

您可以尝试的另一种途径是通过:

-(void)pickerView:(UIPickerView  *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

在该方法中,您将检查 pickerView 中的特定组件是否具有有效的选择。如果没有,则将特定组件(列 - 为什么他们不直接这样称呼它)重置为有效行:

[pickerView selectRow:validRow inComponent:component animated:YES];

这将产生这样的效果:如果用户选择特定的无效行,它将向上滚动(或向下)到一个有效的。

此外,您可以更改相关组件的数据集,然后执行以下操作:

[pickerView reloadAllComponents];

请记住,当您设置选取器时,您必须在第一次运行时进行此验证,因此确保数据集中没有无效数据集默认情况下选择器视图。

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:

-(void)pickerView:(UIPickerView  *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

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:

[pickerView selectRow:validRow inComponent:component animated:YES];

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:

[pickerView reloadAllComponents];

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.

故事灯 2024-10-06 10:09:58

您将必须编写自定义选择器视图

You are going to have to write a custom picker view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文