I have a class which works with social networks related stuff. At some point it may want to put up a UIWebView modally. It may not know which view controller is working at the moment. May I show WebView through UIWindow?
1 Answers
Try doing:
[[UIApplication sharedApplication].keyWindow.rootViewController
presentModalViewController:yourVC animated:YES]
keyWindow
The application's key window. (read-only)
@property(nonatomic, readonly) UIWindow *keyWindow
Discussion
This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.
Availability
Available in iOS 2.0 and later.
UIWindow rootViewController Docs:
rootViewController
The root view controller for the window.
@property(nonatomic, retain) UIViewController *rootViewController
Discussion
The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
The default value of this property is nil.
Availability
Available in iOS 4.0 and later.

- 26,946
- 12
- 75
- 101
-
[UIApplication keyWindow] creates a error, saying there is no such property as keyWindow on object UIApplication? – Ilya Lapan Apr 04 '12 at 14:41
-
Oh, it's [UIApplication sharedApplication].keyWindow! Thanks – Ilya Lapan Apr 04 '12 at 14:43
-
@IlyaLapan Opps. Forgot to add the singleton accessor for UIApplication like you pointed out. I updated my answer. Glad I could help. – Sam Apr 04 '12 at 14:50