Note that there are some explanatory texts on larger screens.

plurals
  1. POXCode: Displaying a UIDatePicker when user clicks on UITextbox
    primarykey
    data
    text
    <p>I have already researched this topic to death and found people posting the exact same question on a number of websites including right <a href="https://stackoverflow.com/questions/6091045/iphone-uidate-popup">here</a> in stackoverflow.</p> <p>I have tried all of the suggestions but have been unable to get the UIDatePicker to actually display. It doesn't seem to matter what approach I take. I've tried using the inheritance model where I subclass the UITextBox control and override it's default methods in order to display the UIDatePicker and then I make sure that in StoryBoard I set the class of my UITextView control to be that custom class. I've tried programmatically generating the UIDatePicker and also tried dragging it onto the view in StoryBoard. When I try the programmatic approach nothing is displayed and when I try dragging it onto the StoryBoard it ALWAYS displays. When I set it's attribute to "hidden" it hides but then I can't get it to show even when I try to add code to the <code>textboxDidBeginEditing</code> method that should unhide it. I've made sure to set the UITextView's inputView property equal to my UIDatePicker control.</p> <p>Nothing works! I don't understand why Apple didn't just make the UIDatePicker one of the default options in the drop down list in the Attributes Inspector for the UITextView control. That would have made this so much easier.</p> <p>Below is some of the code from my implementation class file.</p> <pre><code>#import "AddTasksViewController.h" @implementation AddTasksViewController @synthesize dueDate; @synthesize description; @synthesize shortTitle; @synthesize datePicker; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.dueDate.inputView = datePicker; } return self; } - (IBAction)dueDateDidBeginEditing:(UITextView *)textField { [textField resignFirstResponder]; [datePicker setFrame:CGRectMake(0,200,320,120)]; [datePicker addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:datePicker]; } </code></pre> <p>Here is what my header file looks like...</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface AddTasksViewController : UIViewController @property (nonatomic, copy) IBOutlet UITextView *dueDate; @property (nonatomic, copy) IBOutlet UITextView *description; @property (nonatomic, copy) IBOutlet UITextView *shortTitle; @property (nonatomic, retain) IBOutlet UIDatePicker *datePicker; - (IBAction)doneEditing:(id)sender; - (IBAction)dateChanged:(id)sender; - (IBAction)dueDateDidBeginEditing:(UITextView *)textField; @end </code></pre> <p>As I've already mentioned, the other approach that I took (i.e. subclassing UITextView) didn't work either. I copied the code provided <a href="http://pastie.org/1983801" rel="nofollow noreferrer">here</a> exactly as it was show. I then added the custom classes called "DateField" to my project (both the header and implementation files) and then replaced the UITextBox declaration for the dueDate with DateField in both my AddTaskViewController.h and AddTaskViewController.m files and made sure that the StoryBoard references were updated to by selecting DateField for the control's class in the Identity Inspector.</p> <p>No matter what I do I cannot get the UIDatePicker to display upon clicking on the UITextView. When I set a breakpoint it does hit the <code>dueDateDidBeginEditing</code> method so I know that something is being triggered. The problem is that I don't understand why a subView is not being showing with the UIDatePicker.</p> <p>Any help would be greatly appreciated as this seemingly straightforward task seems to be taking much, much longer than it should. I could do this sort of stuff with my eyes closed and hands tied behind my back in Java and C# yet everything is so unnecessarily complicated when it comes to Objective-C. The syntax really irritates me. </p> <p>So many square brackets!!! Arghhhh!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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