I am using Xcode 6 to develop an iOS Application.
When I used UIAlertController
, it can be worked well on iPhone 6 simulator, but crashes on iPad simula
I am also face same issue and finally got the solution. Here is my solution for Objective-C:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Select you option:"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action = [UIAlertAction actionWithTitle:@“share”
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// do other things
}];
[alertController addAction:action];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
}];
[alertController addAction:cancelAction];
// 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];