I have this code in the UIVIewController (Xcode 6.1, iOS 8.1.1):
[UIAlertController showActionSheetInViewController:self withTitle:@"Test Action Sheet" message:NSLocalizedString(@"Are you sure you want to delete ALL appointments?",nil) cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Yes" otherButtonTitles:@[@"No"] // same as Cancel tapBlock:^(UIAlertController *controller, UIAlertAction *action, NSInteger buttonIndex){ if (buttonIndex == UIAlertControllerBlocksCancelButtonIndex) { NSLog(@"Cancel Tapped"); } else if (buttonIndex == UIAlertControllerBlocksDestructiveButtonIndex) { NSLog(@"Delete Tapped"); } else if (buttonIndex >= UIAlertControllerBlocksFirstOtherButtonIndex) { NSLog(@"Other Action Index %ld", (long)buttonIndex - UIAlertControllerBlocksFirstOtherButtonIndex); } }];
When I run it, I get this error at runtime:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x7fdfe3324f00>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
What do I need to do to make this work? (I looked at SO and Google and did not find anything specific). I appreciate any help I can get from this ...
UPDATE I rewrote it without third-party code; this code is added and now it works!
UIAlertController * view= [UIAlertController alertControllerWithTitle:@"My Title" message:@"Select your Choice" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { //Do some thing here [view dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [view dismissViewControllerAnimated:YES completion:nil]; }]; [view addAction:ok]; [view addAction:cancel]; view.popoverPresentationController.sourceView = self.view; view.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 1.0, 1.0); [self presentViewController: view animated:YES completion:nil];
source share