1

I want to present a view controller from the app delegate that appears above everything, including any modal views open.

I'd be doing this when a push notification arrives.

test *fixtureViewController = [[test alloc] init];

[self.window.rootViewController presentViewController:testViewController animated:YES completion:nil];

But this doesn't work if there is a modal view active from another view controller.

Any ideas?

objectiveccoder001
  • 2,981
  • 10
  • 48
  • 72

3 Answers3

7

Try this one:

+ (UIViewController*) topMostController {
    UIViewController *topController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }
    return topController;
}

With this method you can find the currently active view controller.

Good Luck

Nikola Kirev
  • 3,152
  • 3
  • 22
  • 30
0

You may have to use the active view controller to present this view and have each view listen for the notification while active. Are you using storyboards? Then you could do this differently. I haven't tried this so I am not positive.

BubbleMop
  • 113
  • 1
  • 5
0

Not sure how your code is done but these are some of the messages you can send to your views;

[[view superview] bringSubviewToFront:testViewController];
[[view superview] sendSubviewToBack:testViewController];

or

[testViewController sendToBack];
[testViewController bringToFront];
Alex
  • 367
  • 2
  • 4
  • 15
  • Not what he is looking for, as it won't go in front of a modal, or even detect anything in front of the controller. – Cœur Jun 18 '13 at 08:23