Take the 2-minute tour ×

I want to do something similar to UIAlertView, ie - without reference to any UIView or UIViewController, present a UIViewController on top of all windows using presentModalViewController.

Looking at the documentation I can't find a way in which this is possible!

In OS4, there is something like this:

UIWindow *window = [UIApplication sharedApplication].keyWindow
UIViewController *rootViewController = window.rootViewController

...but this is not possible in OS3.

Does anyone know how to achieve the same effect in OS3?


OK - so I solved this with a myriad of delegate callbacks to the ViewController itself! Although it's the proper way to achieve this, it did seem kind-of odd that's it's not possible at any stage in execution get a handle to the top View Controller for alerts (etc).

If anyone knows how to achieve this, I'd be still really interested!

share|improve this question

1 Answer 1

up vote 19 down vote accepted

UIAlertView creates its own UIWindow above your application's main window, makeKeyAndVisible-s it, and animates in its own views in that window.

share|improve this answer
Ahh - eye opening! Thank you for this! Nick –  Nick Cartwright Sep 17 '10 at 7:46
What/who retains the UIWindow instance? When I create an instance of UIWindow but do not retain it as an instance variable/property it never appears and also seems to be dropped from the [[UIApplication sharedApplication] windows] array. Am I missing something? –  Chris Wagner Mar 8 '13 at 9:31
Ok so in an attempt to create an overlay that acts similar to UIAlertView, I made my UIWindow subclass effectively retain itself by creating a retain cycle. I am assigning self to a strong property, then in my dismiss method I set that property to nil. Seems to work, is this a bad idea? I am assuming UIAlertView does something similar. –  Chris Wagner Mar 8 '13 at 9:49
@ChrisWagner Bad idea. Internally, there is a _UIAlertManager which handles these issues. When you call show and hide, it takes charge and creates the windows, retains them and is responsible for releasing them. –  Leo Natan Sep 7 '13 at 7:13
Who retains the _UIAlertManager? Is it a singleton? –  Chris Wagner Sep 7 '13 at 17:09

Your Answer


