2012-07-31 95 views
2

我在通用應用上顯示UIDatePicker。在iPhone上它顯示得很好,在iPad上它只顯示底部。我在應用程序的其他部分使用UIActionSheet,這兩個應用程序都顯示正常。 如何讓它在iPad上正確顯示?UIDatePicker在iPad上顯示奇怪,但在iPhone上很好

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

回答

1

這很容易,動作片應該有唯一的按鈕內,沒有其他組件。它的大小可能是從按鈕的數量計算出來的。您沒有添加任何按鈕,因此操作表的大小爲零。使用UIPopoverController代替UIActionSheet

+0

IIRC,UIActionSheet默認爲在iPad酥料餅的控制器。 – Bot 2012-07-31 16:51:21

+0

它們以相同的方式顯示,但內容處理方式不同。知道區別。將日期選擇器添加到操作表中不是您應該做的事情。 – Sulthan 2012-07-31 16:54:04

+0

那麼你能給我一個例子,說明如何爲通用應用程序完成這項工作嗎?我猜我需要刪除iphone上的UIActionSheet,並顯示視圖,併爲iPad顯示在一個popoverController。 – Bot 2012-07-31 17:43:54

相關問題