Double tap outside action sheet popover presented using UIAlertController leads to going back to parent view in ios8 xcode 6 beta 5
Asked Answered
O

1

5

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];
});
Oersted answered 16/9, 2014 at 9:22 Comment(1)
I just experienced the same problem using a popover presentation controller; double tapping outside the popover is creating this unexpected (and unwelcome) side effect. Looking for solutions now...Erdmann
E
13

The following solution worked for me in my popover presentation controller scenario; I suspect the same bug underlies your situation:

  1. Set a delegate (conforms to UIPopoverPresentationControllerDelegate protocol) on your UIPopoverPresentationController.
  2. Implement the delegate method 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.
Erdmann answered 28/9, 2014 at 14:1 Comment(3)
This workaround is working for me employing Xcode 6.0.1 (6A317).Erdmann
rdar://18481560 filed with Apple and visible on Open Radar here.Erdmann
FYI - My radar was marked as a dupe by Apple, so I'm sure others are reporting this in volume and a proper fix will be coming in the near future.Erdmann

© 2022 - 2024 — McMap. All rights reserved.