UIDatePicker在iPad上表现得很奇怪但在iPhone上表现不错

时间:2012-07-31 16:45:16

标签: iphone objective-c ipad ios5 uidatepicker

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

2 个答案:

答案 0 :(得分:1)

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

使用UIPopoverController代替UIActionSheet

答案 1 :(得分:0)