UIPickerView关于选择第一个值的问题
我成功实现了 UIPickerView。 但是,我在选择值时遇到问题。
根据标准方式,我已经实现了该方法
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// method implementation...
}
问题是当我尝试选择第一个值时。默认情况下,第一项被选中,因此如果我希望为第一行调用该方法,我必须向下滚动,选择一个值,然后再次向上滚动到第一个值。 我在这里缺少什么?还有另一种方法可以做到这一点吗? 另外,是否可以在不移动选择器的情况下获取所选值?因为我有一个包含 UITextField 和 UIPickerView 等组件的视图,并且我需要扫描整个视图以获取组件值。
谢谢 列奥纳多
I succesfully implemented a UIPickerView.
However, I have a problem in selecting values.
According to the standard way, I have implemented the method
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// method implementation...
}
The problem is when I try to select the very first value. By default the first item is selected, so if I want the method to be called for the first row I have to scroll down, select a value, then scroll up to the first one again.
What am I missing here ? Is there another way of doing this ?
Also, is it possible to get selected value without moving the picker ? Because I have a view containing components as UITextField and UIPickerView and I am in need of scanning the whole view for getting components values.
thanks
Leonardo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 selectedRowInComponent: 方法来获取选择,而无需等待使用操作。
或者,如果您想要用户操作,您可以在某处添加一个空白(或使用当前或无选择等)行,并使用 selectRow:inComponent:animated: 方法来选择该行。
You could use the selectedRowInComponent: method to get the selection without waiting for a use action.
Or if you want a user action, you could add a blank (or use-current, or no-selection, etc.) row somewhere and use the selectRow:inComponent:animated: method to select that.