2011-05-09 120 views
15

在我的應用的iPhone版中,我有一個UIDatePickerUIActionSheet。它看起來正確。我現在正在設置應用程序的iPad版本,並且在iPad上查看時相同的UIActionSheet顯示爲空白空白框。iPad上的UIActionSheet中的UIDatePicker

這裏是我使用的代碼:

UIDatePicker *datePickerView = [[UIDatePicker alloc] init]; 
    datePickerView.datePickerMode = UIDatePickerModeDate; 

    self.dateActionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose a Follow-up Date" 
                delegate:self cancelButtonTitle:nil 
            destructiveButtonTitle:nil otherButtonTitles:@"Done", nil]; 

    [self.dateActionSheet showInView:self.view]; 
    [self.dateActionSheet addSubview:datePickerView]; 
    [self.dateActionSheet sendSubviewToBack:datePickerView]; 
    [self.dateActionSheet setBounds:CGRectMake(0,0,320, 500)]; 

    CGRect pickerRect = datePickerView.bounds; 
    pickerRect.origin.y = -95; 
    datePickerView.bounds = pickerRect; 
+2

問題幫助我瞭解蘋果如何預計用戶使用Popovers和iPad上的ActionSheets比他們的文檔要好得多。謝謝。 – decoy 2011-09-28 11:23:25

+0

檢查我的答案,它可能會使用完整給你。 https://stackoverflow.com/a/7343106/815179 – Narayana 2017-08-28 17:26:52

+0

謝謝@Narayana,但這個問題是從6年前:-) – Chris 2017-08-29 15:14:12

回答

21

我結束了創建的代碼爲iPad酥料餅的一個獨立的部分:

//build our custom popover view 
UIViewController* popoverContent = [[UIViewController alloc] init]; 
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)]; 
popoverView.backgroundColor = [UIColor whiteColor]; 

datePicker.frame = CGRectMake(0, 44, 320, 300); 

[popoverView addSubview:toolbar]; 
[popoverView addSubview:datePicker]; 
popoverContent.view = popoverView; 

//resize the popover view shown 
//in the current view to the view's size 
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244); 

//create a popover controller 
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent]; 

//present the popover view non-modal with a 
//refrence to the button pressed within the current view 
[popoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem 
          permittedArrowDirections:UIPopoverArrowDirectionAny 
              animated:YES]; 

//release the popover content 
[popoverView release]; 
[popoverContent release]; 
+1

這很棒,但是我在日期選取器上方看到空白框。有人知道我怎麼可以用這個房地產嗎?我想在這裏設置一個標題。 – AbuZubair 2012-12-05 01:25:54

+0

@AbuZubair你可能只需要在CGRect上設置一個負值,這樣一個標籤就會出現在未使用的空間 - 哈希,但它可能正常工作。 : - / – 2013-08-06 19:53:22