2

I am showing a UIDatePicker on a universal app. On iPhone it shows fine, on iPad it shows only the bottom portion. I am using UIActionSheet in other portions of the app which display fine on both. How do I get it to display properly on the iPad?

iPhone iPad

- (void)showDatePicker
{   
    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                              delegate:nil
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];


    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]];
    [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
    NSString *dateTimeString = [NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString];

    datePicker.date = [dateFormatter dateFromString:dateTimeString];
    [actionSheet addSubview:datePicker];

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:closeButton];

    [actionSheet showInView:self.view];

    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
Bot
  • 11,868
  • 11
  • 75
  • 131

2 Answers2

1

It's easy, action sheet is supposed to have only buttons inside, not other components. Its size is probably calculated from the number of buttons. You are not adding any buttons so the size of the action sheet is zero.

Use UIPopoverController instead of UIActionSheet.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • IIRC, UIActionSheet defaults to popover controller on iPad. – Bot Jul 31 '12 at 16:51
  • They are displayed in the same way but the contents are handled differently. Know the difference. Adding a date picker into an action sheet is not something you should do. – Sulthan Jul 31 '12 at 16:54
  • So can you give me an example of how this should be done for a universal app? I'm guessing I need to remove the UIActionSheet on iphone and just display the view, and for iPad show it in a popoverController. – Bot Jul 31 '12 at 17:43
0

Check this answer. This is what you want to do with your code.

Displaying a UIDatePicker inside of a UIPopover

UIDatePicker not rendering properly for certain modes in UIPopoverController

Community
  • 1
  • 1
AAV
  • 3,785
  • 8
  • 32
  • 59