i'm using UIAlertController
. But on iPad with iOS 8, actionSheet show with popover arrow. Any ideas to hide that arrow?
Here is my code:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"this is alert controller" message:@"yeah" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];
UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Delete", @"Delete action")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"Delete action");
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[alertController addAction:deleteAction];
UIPopoverPresentationController *popover = alertController.popoverPresentationController;
if (popover) {
popover.sourceView = self.view;
popover.sourceRect = self.view.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionUnknown;
}
[self presentViewController:alertController animated:YES completion:nil];
The selected answer does not center the alert if you have a nav/status bar. To exactly center your alert controller:
With the convenience method:
Also, the alert controller does not stay centered if the view is rotated. To keep the alert controller centered you need to update the sourceRect after rotation. For example:
Or, if you do not want to use rotation events, you can use the
popoverPresentationController
delegate method to reposition the popover:Solution :
use below line for remove arrow from action sheet
Sample
Output
Jageen's answer, in Swift:
You're on the wrong track using UIPopoverPresentationController to display an alert. You just do not need that snipped of code...