I have a action sheet which i am presenting using UIAlertcontroller in ios8 (xcode 6 beta 5). I am using UIAlertcontroller because UIActionsheet ( which is deprecated in iOS 8 ) was not working properly in ios8, on click of any option in the actionsheet leaded me back to the parent view. Now I am facing one issue in UIAlertcontroller too, double tap outside the action sheet popover is leading me back to the previous parent view. Following is my code snippet:
UIAlertController *actionSheetIos8;
actionSheetIos8 = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
NSArray *buttonsArray = [self returnMoreArray];
int startY = 10;
for (int i = 0; i < [buttonsArray count]; i++) {
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:[buttonsArray objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *newStr = [buttonsArray objectAtIndex:i];
newStr = [[newStr lowercaseString] stringByReplacingOccurrencesOfString:@" " withString:@"_"];
}];
[actionSheetIos8 addAction:defaultAction];
}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}];
[actionSheetIos8 setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [actionSheetIos8
popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = [sender frame];
dispatch_async(dispatch_get_main_queue(), ^ {
[self presentViewController:actionSheetIos8 animated:YES completion:nil];
});
The following solution worked for me in my popover presentation controller scenario; I suspect the same bug underlies your situation:
UIPopoverPresentationControllerDelegate
protocol) on your UIPopoverPresentationController
.popoverPresentationControllerShouldDismissPopover:
.For example:
/**
The presence of this delegate callback inhibits the popover presentation controller
from mistakenly calling 'dismissViewControllerAnimated:completion:' on us twice.
*/
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
{
NSLog(@"delegate method called asking permission to dismiss popover");
return YES;
}
Here's more context, where I'm setting up my popover presentation controller with a presented controller and a delegate:
// Set modal presentation style and issue the presentViewController:animated:completion:
// call before retrieving popover presentation controller created for us, as suggested
// in the API documentation that is more recent than the sample code from the
// WWDC2014 slides in Session 228:
presentedController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:presentedController animated:YES completion:nil];
// Now we can retrieve the popover presentation controller and configure it:
UIPopoverPresentationController *popPC = presentedController.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
CGRect popoverRect = cell.infoButton.bounds; // Assume 'cell' exists; it's an object of mine with an 'infoButton' view.
popPC.sourceView = cell.infoButton; // has to be provided along with sourceRect
popPC.sourceRect = popoverRect; // has to be provided along with sourceView
popPC.delegate = self; // or whomever you set to be your popover presentation controller delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With