我在通用應用上顯示UIDatePicker
。在iPhone上它顯示得很好,在iPad上它只顯示底部。我在應用程序的其他部分使用UIActionSheet
,這兩個應用程序都顯示正常。 如何讓它在iPad上正確顯示?UIDatePicker在iPad上顯示奇怪,但在iPhone上很好
- (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)];
}
IIRC,UIActionSheet默認爲在iPad酥料餅的控制器。 – Bot 2012-07-31 16:51:21
它們以相同的方式顯示,但內容處理方式不同。知道區別。將日期選擇器添加到操作表中不是您應該做的事情。 – Sulthan 2012-07-31 16:54:04
那麼你能給我一個例子,說明如何爲通用應用程序完成這項工作嗎?我猜我需要刪除iphone上的UIActionSheet,並顯示視圖,併爲iPad顯示在一個popoverController。 – Bot 2012-07-31 17:43:54