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)];
}
4

2 回答 2

1

很简单,操作表应该只有按钮,没有其他组件。它的大小可能是根据按钮的数量来计算的。您没有添加任何按钮,因此操作表的大小为零。

使用UIPopoverController而不是UIActionSheet.

于 2012-07-31T16:49:26.967 回答
0

检查这个答案。这就是您要对代码执行的操作。

在 UIPopover 内显示 UIDatePicker

UIDatePicker 在 UIPopoverController 中的某些模式下无法正确呈现

于 2012-07-31T16:53:01.303 回答