iphone UIpicker 有 2 个组件同时滚动
我想创建一个包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这种即时同步是不可能的。您可以通过适当响应以下 UIPickerViewDelegate 方法来保持两个组件同步:
唯一的问题是该函数在滚轮完成移动后几毫秒被调用,因此您只能在滚轮停止移动后才能同步它们。
因此,您可能会延迟同步(只需查看当您尝试插入不正确的日期(例如 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:
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).