iphone - UIDatePicker 在 iPad 上显示很奇怪,但在 iPhone 上显示正常

标签 iphone objective-c ipad ios5 uidatepicker

我在通用应用程序上显示UIDatePicker。在 iPhone 上显示良好,在 iPad 上仅显示底部部分。我在应用程序的其他部分使用 UIActionSheet ,这两个部分都显示良好。 如何让它在 iPad 上正确显示?

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)];
}

最佳答案

很简单,操作表中应该只有按钮,而不是其他组件。它的大小大概是根据按钮的数量来计算的。您没有添加任何按钮,因此操作表的大小为零。

使用UIPopoverController而不是UIActionSheet

关于iphone - UIDatePicker 在 iPad 上显示很奇怪,但在 iPhone 上显示正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11745067/

相关文章:

iphone - 如何通过点击外部来关闭 UITextView?

iphone - Objective C - 将对象数组(带有日期字段)转换为数组字典(按星期几键控)

ios - SQLite 数据库在更新时挂起

ios - 您如何管理 iOS 项目中的 View 标签?

ios - 应用程序看起来像主从行为就像标签栏 Controller

iPhone - 用于计算的正确 UI 控件

iphone - iOS - 是否有可能 [NSData dataWithContentsOfURL :url] would return only part of the bytes of the content?

ios - 在 iOS 中使用本地播放器播放来自网络的视频

ios - xcode 8 中的 btnactionsender 而不是 btnaction

iphone - 如何为 iPhone 应用程序循环播放声音?