我正在通用应用程序上显示UIDatePicker。在iPhone上显示正常,在iPad上仅显示底部。我在应用程序的其他部分中使用UIActionSheet,两者均显示正常。如何使它在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)];
}

最佳答案

很简单,应该在操作表中仅包含按钮,而不包含其他组件。它的大小可能是通过按钮的数量来计算的。您没有添加任何按钮,因此操作表的大小为零。

使用UIPopoverController代替UIActionSheet

关于iphone - UIDatePicker在iPad上显示很奇怪,但在iPhone上很好,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11745067/

10-13 05:34