1

I implemented the UIDatePicker in iPhone and it's working correctly.

The same code I tried with iPad but it is not showing me UIDatePicker.

I read somewhere that I need to show it with UIPopOverController and find this link but it is not showing the proper code.

I can't make a separate XIB for that. I have to implement it by code itself. Mine is IOS5.

I use the following code:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.tag == 1)
    {
            [self showDatePickerIniPad];
      }
}
   -(void)showDatePickerIniPad
 {
     UIViewController *popoverContent = [[UIViewController alloc] init];
     UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     popoverView.backgroundColor = [UIColor whiteColor];
     datePicker.frame = CGRectMake(0, 0, 320, 300);
     [popoverView addSubview:datePicker];
     popoverContent.view = popoverView;
     popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

     UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
     [popoverController presentPopoverFromRect:CGRectZero inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

     txt_FromDate.inputView = datePicker;
 }
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
Heena
  • 2,348
  • 3
  • 32
  • 58

2 Answers2

0

If you want the popover to show when you click on the textfield you are doing in the right method, - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField.The problem is this is a Delegate Method for the textField so you should include the UITextFieldDelegate in you interface in the .h file

@interface myViewController : UIViewController<UITextFieldDelegate>{

and set the delegate of you text field like this

self.yourTextField.delegate = self;

That should solve your problem.

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
David Cespedes
  • 520
  • 1
  • 6
  • 14
0

Since your question is more on the lines of learning rather than a specific doubt or question, i am posting tutorial links. These 2 tutorials should solve your problem(s) -

UIPickerView Basics

UIDateView Components

UPDATE: Also check these highly relevant links from stackoverlfow itself -

UIDatePicker in UIActionSheet on iPad

https://stackoverflow.com/questions/5830585/uidatepicker-inside-uiactionsheet-ipad

blank UIDatePicker on iPad in mode UIDatePickerModeDateAndTime

Community
  • 1
  • 1
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • In your example UIDatePicker is put in XIB, I have to show it on UITextField click.I did code for iphone but picker not being shown in ipad – Heena Dec 02 '11 at 10:28
  • I used the code of 1st link. But I didn't get how can I set it show on textfield click.I used for iphone `txtbox.inputview=datePicker` but for UIPopViewController I wont be able to use that – Heena Dec 02 '11 at 10:44