【问题标题】:iPad Actionsheet not showingiPad 操作表未显示
【发布时间】:2014-01-18 09:51:43
【问题描述】:

我正在尝试在 iPad 中显示包含 2 个按钮和日期选择器视图的操作表。

我在 iphone 中正确显示了操作表,但是当我尝试在 iPad 中显示操作表时,它只显示一条粗黑线。

目前它看起来像:

显示操作表的代码是

    UIButton *btnClicked=(UIButton *)sender;
    menu = [[UIActionSheet alloc] initWithTitle:nil
                                       delegate:self
                              cancelButtonTitle:nil
                         destructiveButtonTitle:nil
                              otherButtonTitles:nil];
   /* menu=[[UIActionSheet alloc] initWithTitle:@"This will remove this recipe from all synced devices as well. Are you sure?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Confirm Delete Recipe" otherButtonTitles:nil];*/
    [menu setTag:121];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,5,300,20)];
    [titleLabel setFont:[UIFont fontWithName:@"Trebuchet MS" size:18.0f]];
    titleLabel.textAlignment = UITextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    [titleLabel setNumberOfLines:1];

    [menu addSubview: titleLabel];

    UIButton *cancelButton = [UIButton buttonWithType: UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(30, 30, 124, 43);
    [cancelButton setBackgroundImage:[UIImage imageNamed:@"cancel_button.png"] forState: UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonClicked:)    forControlEvents:UIControlEventTouchUpInside];
    cancelButton.adjustsImageWhenHighlighted = YES;
    cancelButton.tag=33;
    [menu addSubview: cancelButton];

    UIButton *okButton = [UIButton buttonWithType: UIButtonTypeCustom];
    okButton.frame = CGRectMake(170, 30, 124, 43);
    [okButton setBackgroundImage:[UIImage imageNamed:@"continue_button.png"] forState: UIControlStateNormal];
    [okButton addTarget:self action:@selector(okButtonClicked:)    forControlEvents:UIControlEventTouchUpInside];
    okButton.adjustsImageWhenHighlighted = YES;

    [menu addSubview: okButton];

    datePickerView = [[UIDatePicker alloc] init];
    CGRect pickerRect = datePickerView.bounds;
    pickerRect.origin.y = 75;
    datePickerView.frame = pickerRect;

    //---Picker view for from date selection
    if (btnClicked.tag==51)
    {
        [titleLabel setText:SELECT_FROM_DATE];
        NSDate *now = [Global todayDate];
        int daysToAdd = 1;
        NSDate *newDate = [now dateByAddingTimeInterval:60*60*24*daysToAdd];
        // NSLog(@"%@",strDtFromDate);
        datePickerView.minimumDate = newDate;
        if (holidayType==2)
        {
            NSDate *holidayFromDate=[dateFormat dateFromString:objectSelectedGroup.fromDate];
           // newDate=[holidayFromDate dateByAddingTimeInterval:60*60*24*daysToAdd];
            if ([[Global todayDate] compare:holidayFromDate] == NSOrderedAscending)
            {
                datePickerView.minimumDate = holidayFromDate;
            }
            else if([[Global todayDate] compare:holidayFromDate] == NSOrderedDescending)
            {
                datePickerView.minimumDate = newDate;
            }
            NSDate *holidayToDate=[dateFormat dateFromString:objectSelectedGroup.toDate];
            NSLog(@"%@",objectSelectedGroup.fromDate);
            NSLog(@"%@",objectSelectedGroup.toDate);

            datePickerView.maximumDate = holidayToDate;

        }

        okButton.tag=34;
    }
    else if(btnClicked.tag==52)
    {
        [titleLabel setText:SELECT_TO_DATE];
        datePickerView.minimumDate=stringDate;
        NSDate *holidayToDate=[dateFormat dateFromString:objectSelectedGroup.toDate];
        datePickerView.maximumDate=holidayToDate;
        okButton.tag=35;
    }
    datePickerView.datePickerMode = UIDatePickerModeDate;
    stringDate=[datePickerView date];
    [datePickerView addTarget:self action:@selector(selectedDateChanged:) forControlEvents:UIControlEventValueChanged];
    [menu addSubview:datePickerView];
    //menu.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
    [menu showInView:self.view];
    [menu setFrame:CGRectMake(0,self.view.frame.size.height - 290,320,290)];

同样的代码在 iphone 上运行良好。 如何解决?

【问题讨论】:

    标签: ios objective-c xcode ipad uiactionsheet


    【解决方案1】:

    使用 PopOver 控制器在 ipad 上显示操作表。要在 Popover 控制器上使用操作表,请参考以下链接,

    UIDatePicker in UIActionSheet on iPad

    UIActionSheet on iPad frame too small

    【讨论】:

    • 谢谢,我很困惑,因为在 iPad UIActionSheet 的一个屏幕上只有按钮可以工作,但在我上面给出的 UIActionSheet 代码的另一个屏幕上不能与 DatePickerView 一起工作。这一行“UIActionSheet 不可调整大小,请尝试在您的代码中使用 [pickerActionSheet addSubview:thePickerView] 注释该行;您将看到 ActionSheet 非常适合按钮。”在您的第二个链接中清除了我的困惑。
    【解决方案2】:

    UIActionaSheet 不适合 iPad,而且它们大多数时候在框架周围表现得无法预测 我会推荐一个带有自定义 UIViewController 的 UIPopoverController 来提供这种用户体验。

    【讨论】:

      【解决方案3】:

      您可以尝试用以下几行替换最后两行,

      [menu setFrame:CGRectMake(0,self.view.frame.size.height - 290,320,290)];
      [menu showInView:[[[UIApplication sharedApplication] delegate] window]];
      

      【讨论】:

        猜你喜欢
        • 2014-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-15
        • 2015-05-09
        • 2014-01-28
        • 1970-01-01
        相关资源
        最近更新 更多