0

我在通用应用程序上显示 UIDatePicker。在 iPhone 上显示正常,在 iPad 上仅显示底部。这是我的代码:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        [aTextField resignFirstResponder];
        pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

        UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 64, 0,0)];
        pickerView.datePickerMode = UIDatePickerModeDate;
        pickerView.hidden = NO;
        pickerView.date = [NSDate date];
        [pickerView addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];

        UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,1024,64)];
        pickerToolbar.barStyle = UIBarStyleBlackOpaque;
        [pickerToolbar sizeToFit];

        NSMutableArray *barItems = [[NSMutableArray alloc] init];
        UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        [barItems addObject:flexSpace];

        UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
        [barItems addObject:doneBtn];

        UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
        [barItems addObject:cancelBtn];

        [pickerToolbar setItems:barItems animated:YES];
        [pickerViewPopup addSubview:pickerToolbar];
        [pickerViewPopup addSubview:pickerView];
        [pickerViewPopup showInView:self.view];
        [pickerViewPopup setBounds:CGRectMake(0,0,1024, 768)];

    }
4

1 回答 1

0

我使用了该代码并且它正在工作

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            [aTextField resignFirstResponder];
            UIViewController *popoverContent = [[UIViewController alloc] init];
            UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
            popoverView.backgroundColor = [UIColor whiteColor];
            UIDatePicker *datePicker=[[UIDatePicker alloc]init];
            datePicker.frame = CGRectMake(0, 0, 320, 300);
            datePicker.datePickerMode = UIDatePickerModeDate;
            datePicker.hidden = NO;
            datePicker.date = [NSDate date];
            [datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];
           [popoverView addSubview:datePicker];
            popoverContent.view = popoverView;
            popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 200);
            UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
            [popoverController presentPopoverFromRect:CGRectMake(0, 0, 1150,480) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
于 2013-08-21T06:53:19.203 回答