Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone display date picker on UITextField touch
    text
    copied!<p>I followed this thread: <a href="https://stackoverflow.com/questions/7308754/datepicker-by-clicking-on-textfield">datepicker by clicking on textfield</a></p> <p>I imported both of the following protocols:</p> <pre><code>@interface ViewController : UIViewController&lt;UIActionSheetDelegate, UITextFieldDelegate&gt; { </code></pre> <p>Then, in the implementation, I use the following:</p> <pre><code>- (void)viewDidLoad { textField.delegate = self; [super viewDidLoad] } </code></pre> <p>Lastly, I put the actual code to display the date picker (from the thread). I also linked it all up in the IB.</p> <pre><code> //Date Picker - (void)textFieldDidBeginEditing:(UITextField *)aTextField{ [aTextField resignFirstResponder]; pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)]; pickerView.datePickerMode = UIDatePickerModeDate; pickerView.hidden = NO; pickerView.date = [NSDate date]; UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; pickerToolbar.barStyle = UIBarStyleBlackOpaque; [pickerToolbar sizeToFit]; NSMutableArray *barItems = [[NSMutableArray alloc] init]; UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; [barItems addObject:flexSpace]; UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]; [barItems addObject:doneBtn]; UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)]; [barItems addObject:cancelBtn]; [pickerToolbar setItems:barItems animated:YES]; [pickerViewPopup addSubview:pickerToolbar]; [pickerViewPopup addSubview:pickerView]; [pickerViewPopup showInView:self.view]; [pickerViewPopup setBounds:CGRectMake(0,0,320, 464)]; } -(void)doneButtonPressed:(id)sender{ //Do something here here with the value selected using [pickerView date] to get that value [pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES]; } -(void)cancelButtonPressed:(id)sender{ [pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES]; } </code></pre> <p>However, when I click on the UITextField, I get this:</p> <p><img src="https://i.stack.imgur.com/OHANh.png" alt="enter image description here"></p> <p>What am I doing wrong?</p>
 

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