<bdo id='1qRT9'></bdo><ul id='1qRT9'></ul>
    <i id='1qRT9'><tr id='1qRT9'><dt id='1qRT9'><q id='1qRT9'><span id='1qRT9'><b id='1qRT9'><form id='1qRT9'><ins id='1qRT9'></ins><ul id='1qRT9'></ul><sub id='1qRT9'></sub></form><legend id='1qRT9'></legend><bdo id='1qRT9'><pre id='1qRT9'><center id='1qRT9'></center></pre></bdo></b><th id='1qRT9'></th></span></q></dt></tr></i><div id='1qRT9'><tfoot id='1qRT9'></tfoot><dl id='1qRT9'><fieldset id='1qRT9'></fieldset></dl></div>
  • <small id='1qRT9'></small><noframes id='1qRT9'>

  • <tfoot id='1qRT9'></tfoot>

      <legend id='1qRT9'><style id='1qRT9'><dir id='1qRT9'><q id='1qRT9'></q></dir></style></legend>

        在点击文本字段时显示日期选择器

        时间:2023-10-03

        1. <legend id='2vNHt'><style id='2vNHt'><dir id='2vNHt'><q id='2vNHt'></q></dir></style></legend>

          <small id='2vNHt'></small><noframes id='2vNHt'>

          <tfoot id='2vNHt'></tfoot>
          • <bdo id='2vNHt'></bdo><ul id='2vNHt'></ul>
            <i id='2vNHt'><tr id='2vNHt'><dt id='2vNHt'><q id='2vNHt'><span id='2vNHt'><b id='2vNHt'><form id='2vNHt'><ins id='2vNHt'></ins><ul id='2vNHt'></ul><sub id='2vNHt'></sub></form><legend id='2vNHt'></legend><bdo id='2vNHt'><pre id='2vNHt'><center id='2vNHt'></center></pre></bdo></b><th id='2vNHt'></th></span></q></dt></tr></i><div id='2vNHt'><tfoot id='2vNHt'></tfoot><dl id='2vNHt'><fieldset id='2vNHt'></fieldset></dl></div>

                  <tbody id='2vNHt'></tbody>
                • 本文介绍了在点击文本字段时显示日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在点击文本框时显示 datetimepicker 控件?

                  How can I display a datetimepicker control on tap of a textbox?

                  我有一个包含到达和离开文本字段的用户界面,当用户点击到达文本框时,它应该会弹出一个 datetimepicker 控件而不是键盘,并且与离开文本框相同.

                  I have a user interface that has arrival and departure text fields, and when a user clicks on arrival textbox it should bring up a datetimepicker control up instead of a keyboard and the same with the departure textbox.

                  推荐答案

                  您可以为此使用文本字段的 inputViewinputAccessoryView 属性.创建日期选择器并将其设置为两个文本字段的输入视图.还为 Done 按钮创建另一个视图,并将其作为辅助视图.您将需要该按钮来关闭输入视图.

                  You can use inputView and inputAccessoryView properties of the text field for this. Create the date picker and set it to the input views of the two text fields. Also create another view for the Done button and it as their accessory view. You will need that button to dismiss the input view.

                  Done 按钮必须连接到基本上执行此操作的功能 -

                  The Done button must be wired up to function which basically does this –

                  if ( [textField1 isFirstResponder] ) {
                      [textField1 resignFirstResponder];
                  } else if ( [textField2 isFirstResponder] ) {
                      [textField2 resignFirstResponder];
                  }
                  

                  另一个选择是继承 UITextField 并覆盖 inputViewinputAccessoryView.当有大量它们时,这是要走的路.

                  Another option would be to subclass UITextField and override inputView and inputAccessoryView. This is the way to go when there are loads of them.

                  示例

                  @interface CustomKeyboardAppDelegate : NSObject <UIApplicationDelegate> {
                  ...
                  
                  @property (nonatomic, retain) IBOutlet UIWindow *window;
                  @property (nonatomic, retain) IBOutlet UITextField *textField;
                  @property (nonatomic, retain) IBOutlet UIToolbar *accessoryView;
                  @property (nonatomic, retain) IBOutlet UIDatePicker *customInput;
                  
                  - (IBAction)dateChanged:(id)sender;
                  - (IBAction)doneEditing:(id)sender;
                  @end
                  

                  在 XIB 中,拉出一个 UIToolbar 和一个 UIDatePicker 但不要将其附加到视图.正确连接插座.dateChanged: 响应日期选择器中的更改,并在单击工具栏中的 Done 按钮时调用 doneEditing:.也连接它们.这些方法的实现如下所列.

                  In the XIB, Pull out a UIToolbar and a UIDatePicker but don't attach it to the view. Connect the outlets appropriately. dateChanged: responds to changes in the date picker and doneEditing: is called when the Done button in the tool bar is clicked. Connect them too. The methods are implemented as listed below.

                  @implementation CustomKeyboardAppDelegate
                  
                  @synthesize window=_window;
                  @synthesize textField = _textField;
                  @synthesize accessoryView = _accessoryView;
                  @synthesize customInput = _customInput;
                  
                  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
                  {
                      self.textField.inputView = self.customInput;
                      self.textField.inputAccessoryView = self.accessoryView;
                      ...    
                  }
                  
                  ...
                  
                  - (IBAction)dateChanged:(id)sender {
                      UIDatePicker *picker = (UIDatePicker *)sender;
                  
                      self.textField.text = [NSString stringWithFormat:@"%@", picker.date];
                  }
                  
                  - (IBAction)doneEditing:(id)sender {
                      [self.textField resignFirstResponder];
                  }
                  @end
                  

                  随着更多的文本字段依赖于这个选择器,最后两种方法会膨胀.

                  The last two methods will bloat up as more text fields depend on this picker.

                  这篇关于在点击文本字段时显示日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在常规 UIViewController 上的 UITableViewCell 中的键盘上方滚动 UITextField 下一篇:NSDateFormatter 在 OS 4.0 中返回 nil

                  相关文章

                  <legend id='G3Noo'><style id='G3Noo'><dir id='G3Noo'><q id='G3Noo'></q></dir></style></legend>

                    1. <small id='G3Noo'></small><noframes id='G3Noo'>

                      <tfoot id='G3Noo'></tfoot>
                    2. <i id='G3Noo'><tr id='G3Noo'><dt id='G3Noo'><q id='G3Noo'><span id='G3Noo'><b id='G3Noo'><form id='G3Noo'><ins id='G3Noo'></ins><ul id='G3Noo'></ul><sub id='G3Noo'></sub></form><legend id='G3Noo'></legend><bdo id='G3Noo'><pre id='G3Noo'><center id='G3Noo'></center></pre></bdo></b><th id='G3Noo'></th></span></q></dt></tr></i><div id='G3Noo'><tfoot id='G3Noo'></tfoot><dl id='G3Noo'><fieldset id='G3Noo'></fieldset></dl></div>
                      • <bdo id='G3Noo'></bdo><ul id='G3Noo'></ul>