Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>inputView</code> and <code>inputAccessoryView</code> 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 <code>Done</code> button and it as their accessory view. You will need that button to dismiss the input view. </p> <p>The <code>Done</code> button must be wired up to function which basically does this –</p> <pre><code>if ( [textField1 isFirstResponder] ) { [textField1 resignFirstResponder]; } else if ( [textField2 isFirstResponder] ) { [textField2 resignFirstResponder]; } </code></pre> <p>Another option would be to subclass <code>UITextField</code> and override <code>inputView</code> and <code>inputAccessoryView</code>. This is the way to go when there are loads of them.</p> <p><strong>Example</strong></p> <pre><code>@interface CustomKeyboardAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { ... @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 </code></pre> <p>In the XIB, Pull out a <code>UIToolbar</code> and a <code>UIDatePicker</code> but don't attach it to the view. Connect the outlets appropriately. <code>dateChanged:</code> responds to changes in the date picker and <code>doneEditing:</code> is called when the <code>Done</code> button in the tool bar is clicked. Connect them too. The methods are implemented as listed below.</p> <pre><code>@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 </code></pre> <p>The last two methods will bloat up as more text fields depend on this picker.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload