iphone - iPad 上 UIActionSheet 中的 UIDatePicker

标签 iphone ipad uidatepicker uiactionsheet

在我的应用程序的 iPhone 版本中,我在 UIActionSheet 中有一个 UIDatePicker。它显示正确。我现在正在设置应用程序的 iPad 版本,在 iPad 上查看时,相同的 UIActionSheet 显示为空白框。

这是我正在使用的代码:

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;

最佳答案

我最终为 iPad Popover 创建了一段单独的代码:

//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];

关于iphone - iPad 上 UIActionSheet 中的 UIDatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5941583/

相关文章:

iphone - 子项目的 Xcode 环境变量

iphone - 我应该使用什么技术来复制 iPhone 应用程序中的撰写电子邮件 View ?

ios - UIDatePicker 内存泄漏与 ARC

iphone - 如何使用 Cocoa (iPhone) 解码 XML 文档中的 shift-jis 编码数据

ios - 403 错误 - 这是一个错误。错误 : disallowed_useragent

iphone - 如何在屏幕解锁后重新启动动画

javascript - HTML5音频的多个实例-我只需要一个实例就可以随时播放

objective-c - 我在UIActivityGroupViewController中遇到各种崩溃,这是UIDocumentInteractionController和UIActivityViewController的一部分

ios - UIDatepicker 巨大的内存分配

ios - 禁用 UITextField 编辑但仍接受触摸 - Swift 3