0

Action sheet is working fine for iPhone but when I tried it on the iPad, it's not working. any solution for this?

My code is below:

-(void)setUpAlertCtrl{
    self.alertCtrl=[UIAlertController alertControllerWithTitle:@"Select Image"
                                                       message:nil
                                                preferredStyle:UIAlertControllerStyleActionSheet];
}
Anyone
  • 2,814
  • 1
  • 22
  • 27

2 Answers2

3

Try this

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

{

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"Your message" preferredStyle:UIAlertControllerStyleActionSheet];

// Remove arrow from action sheet.
[alertController.popoverPresentationController setPermittedArrowDirections:0];
//For set action sheet to middle of view.
CGRect rect = self.view.frame;
rect.origin.x = self.view.frame.size.width / 20;
rect.origin.y = self.view.frame.size.height / 20;
alertController.popoverPresentationController.sourceView = self.view;
alertController.popoverPresentationController.sourceRect = rect;

[self presentViewController:alertController animated:YES completion:nil];    }

}

Kiran eldho
  • 224
  • 1
  • 8
1

Plz use this code it will be help you In ipad you have to set actionsheet as popover presentation

   UIAlertController *alertController=[UIAlertController alertControllerWithTitle:nil message:@"Select Sorting Type" preferredStyle:(UIAlertControllerStyleActionSheet)];

            UIAlertAction *Date_action=[UIAlertAction actionWithTitle:@"Date" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
               //action on click

            }];

            UIAlertAction *title_action=[UIAlertAction actionWithTitle:@"Title" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

                //action on click

            }];

            UIAlertAction *cancel_action=[UIAlertAction actionWithTitle:@"Cancel" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
                //action on click
            }];

            [alertController addAction:Date_action];
            [alertController addAction:title_action];
            [alertController addAction:cancel_action];

            if (Is_IPad) {

                UIPopoverPresentationController *popPresenter = [alertController
                                                                 popoverPresentationController];
//provide source view to actionsheet as popover presentation

                popPresenter.sourceView = sender;
                popPresenter.sourceRect = sender.bounds;
                [self presentViewController:alertController animated:YES completion:nil];

            }else{
                [self presentViewController:alertController animated:YES completion:nil];
            }
Ajharudeen khan
  • 246
  • 2
  • 10