Question

I am attempting to display a passcode screen that appears after X amount of inactivity. I use presentViewController:animated:completion: on the root view controller, and it works as expected, except when a popover is already being displayed. The popover, displayed from a bar button item, appears over the presented passcode screen.

Is there a way to dismiss or hide all visible popovers when presenting a view controller?

Was it helpful?

Solution

Create and add a 2nd window over the first. Present the passcode screen in the 2nd window. This will allow it to appear over any and all views from the first window. When you dismiss the passcode screen, be sure to remove the new window and make the 1st one key again.

OTHER TIPS

Do you have a reference to the popover? Then you can just call

[popover dismissPopoverAnimated:NO];

when you go to shop the passcode overlay.

EDIT

Looping through subviews and seeing if you can dimiss a popover. I'd really recommend trying to find some other way of doing things as this is just icky. But it should work (untested).

for (UIView* view in self.view.subviews) {
    if([view respondsToSelector:@selector(dismissPopoverAnimated:)]){
        [(UIPopoverController*)view dismissPopoverAnimated:NO];
    }
}

NSNotifications are a good tool for this problem. Have all your views or controllers that present popovers listen for a notification named, say, WillPresentPasscodeScreen, and implement a method that dismisses the popover when the notification comes in. Then, before you present your passcode VC, post a WillPresentPasscodeScreen notification -- no more popovers, regardless of where you are in the app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top