2012-07-31 99 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

相关问题