UIPickerView 在 TextField 上实时更新

发布于 2024-11-13 08:11:17 字数 324 浏览 3 评论 0原文

一旦我滚动 PickerView(或)UIDatePicker,我就需要将值显示在 TextField 上:

  1. 滚动时。即使选择器移动,文本字段也应该自行更新。这可能吗?

  2. 当拾取器停止移动并停止时。是否有一个让 PickerView 停止的事件,以便我可以更新文本字段(一旦 pickerView 停止)。

     // 我不想使用 TextFieldDidEndEditing 
     // 我希望文本字段在选择器视图停止时自动更新。 
    

如果有人能解决 1) 和 2),那将会很有帮助

As soon as I scroll the PickerView (or) UIDatePicker, I need the value to get displayed on a TextField :

  1. While Scrolling. Even when the picker is moving the text field should update itself. Is it possible ?

  2. On the event that the Picker stops moving and comes to rest. Is there an event for the PickerView to come to rest so that I could update the textField (as soon as the pickerView comes to rest).

      // I do not wish to use the TextFieldDidEndEditing 
     // I want the textField to update itself when the picker view comes to rest. 
    

It would be helpful if anyone could solve 1) and 2)

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

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

发布评论

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

评论(2

無心 2024-11-20 08:11:17

(1) 可能不可能。对于(2),您可以使用委托方法pickerView:didSelectRow:inComponent。如果您需要任何帮助,请告诉我。

对于UIPickerView

(1)实现pickerView:titleForRow:forComponent

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    // Every time the picker view is rotated, this method will be called to fetch the title.
    NSInteger selectedRow = [pickerView selectedRowInComponent:0];
    // Get selected row like above and process data and update text field.


    [..] // Process the title
    return the title.
}

(2)这样就比较明显了。

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
   // You have the selected row, update the text field.
}

(1) might not be possible. For (2), you can use the delegate method pickerView:didSelectRow:inComponent. Let me know if you need any help with this.

For UIPickerView

(1) Implement pickerView:titleForRow:forComponent,

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    // Every time the picker view is rotated, this method will be called to fetch the title.
    NSInteger selectedRow = [pickerView selectedRowInComponent:0];
    // Get selected row like above and process data and update text field.


    [..] // Process the title
    return the title.
}

(2) This is more obvious.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
   // You have the selected row, update the text field.
}
空心空情空意 2024-11-20 08:11:17

对于第一个问题,这对于默认控件是不可能的,但是没有什么可以阻止您编写自己的控件并使用 touchesMoved 等来模拟效果...

For the first question, this isn't possible with the default control however there is nothing to stop you writing your own and simulate the effect using touchesMoved etc...

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