1

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?

livings124
  • 1,103
  • 1
  • 10
  • 23

3 Answers3

1

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];
    }
}
Josh
  • 3,445
  • 5
  • 37
  • 55
  • I was hoping to make this more generic. There are a lot of potential views with a lot of unrelated popovers. – livings124 Jun 05 '13 at 15:27
  • There's a really nasty way of doing it, by looping through all subviews and seeing if it responds to dismissPopoverAnimated:. See edit. – Josh Jun 05 '13 at 15:52
  • I figured that would be a way. I've looked at looping through the view controllers child view controllers until I found a UIPopoverController - it seems that the popover controller has a parent view controller, but that same view controller doesn't have the UIPopoverController as a child view controller. Any idea why that would be? – livings124 Jun 05 '13 at 17:36
  • I'm not exactly sure, my guess would be that child view controllers are related to view controller containment (think tab bars) where as parent view controllers are somehow different. Sorry I can't be any more helpful. – Josh Jun 06 '13 at 11:11
1

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • How would I add this window? UIApplication's windows property looks to be readonly. – livings124 Jun 05 '13 at 19:37
  • It looks like makeKeyAndVisible does it automatically. This seems to work - the only issue is that the buttons in the view controller I set as the rootViewController don't respond to touch (and I explicitly set enableUserInteraction). – livings124 Jun 05 '13 at 19:49
  • Solved the responding to touch issue by explicitly setting the size of the window. Thanks! – livings124 Jun 05 '13 at 20:17
1

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.

Joe Hankin
  • 950
  • 8
  • 15