// Show a dialog with an "Okay" and "Cancel" button.
- (void)showOkayCancelActionSheet:(NSIndexPath *)selectedPath {
NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);
NSString *destructiveButtonTitle = NSLocalizedString(@"OK", nil);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
// Create the actions.
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"The \"Okay/Cancel\" alert action sheet's cancel action occured.");
}];
UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"The \"Okay/Cancel\" alert action sheet's destructive action occured.");
}];
// Add the actions.
[alertController addAction:cancelAction];
[alertController addAction:destructiveAction];
// Configure the alert controller's popover presentation controller if it has one.
UIPopoverPresentationController *popoverPresentationController = [alertController popoverPresentationController];
if (popoverPresentationController) {
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:selectedPath];
popoverPresentationController.sourceRect = selectedCell.frame;
popoverPresentationController.sourceView = self.view;
popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
}
[self presentViewController:alertController animated:YES completion:nil];
}
No comments:
Post a Comment