iphone UIpicker 有 2 个组件同时滚动

发布于 2024-10-15 10:01:08 字数 198 浏览 1 评论 0原文

我想创建一个包含 2 个组件的 UIPicker,它们都会有数字。在第一个左侧选择器中选择的数字必须小于(或等于)在第二个选择器中选择的数字。我希望这两个组件同步,如果我向下滚动,例如第一个,并且第一个列中选定的数字等于第二列中选定的数字,那么我希望当我时第二列自动向下滚动继续在第一个中向下滚动。我是 iPhone 开发新手,你能帮我提供代码吗?非常感谢!

丹尼尔

I would like to create a UIPicker with 2 components, there will be numbers in both of them. The number selected in the first, left picker must be lower (or equal) than the number selected in the second one. I want these two components to be synchronized, if I scroll down for example the fisrt one, and the selected number in the fisrt coloumn equals to the number selected in the second coloumn, then I want the second coloumn to be scrolled down automatically when I continue scrolling down in the first one. Im new to iphone development, could you help me with a code? Thank you very much!

Daniel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

初吻给了烟 2024-10-22 10:01:08

我认为这种即时同步是不可能的。您可以通过适当响应以下 UIPickerViewDelegate 方法来保持两个组件同步:

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

唯一的问题是该函数在滚轮完成移动后几毫秒被调用,因此您只能在滚轮停止移动后才能同步它们。
因此,您可能会延迟同步(只需查看当您尝试插入不正确的日期(例如 6 月 31 日)时的 UIDatePicker 行为),但不是即时同步(除非您构建完全自定义的视图)。

I don't think this instant synchronization is possible. You can keep two components in sync by appropriately responding to the following UIPickerViewDelegate method:

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

the only issue is that this function is called a few milliseconds after the wheel finish its movement, so you can sync the wheels only after they did stop their movement.
So you may have delayed synchronization (just look at the UIDatePicker behaviour when you try to insert incorrect dates, such as 31 June), but not instant one (unless you build a completely custom view).

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