Search code examples
iosobjective-cxcodeipaduiactionsheet

iPad Actionsheet not showing


I am trying to display action sheet in iPad which will contain 2 buttons and date pickerview.

I displayed the action sheet in iphone properly but when I try to display the action sheet in iPad its just displaying one thick black line.

Currently its looking like :

enter image description here

and code for displaying action sheet is

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

And same code is working fine for iphone. How to solve this?


Solution

  • Use PopOver Controller to display action sheet on ipad. To use actionsheet on Popover controller refer the following links,

    UIDatePicker in UIActionSheet on iPad

    UIActionSheet on iPad frame too small