Search code examples
objective-ciosviewmodal-dialoguiwindow

Showing a UIWebView modally on top of whole application through UIWindow from class inherited from NSObject?


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?


Solution

  • Try doing:

    [[UIApplication sharedApplication].keyWindow.rootViewController 
      presentModalViewController:yourVC animated:YES]
    

    UIApplication keyWindow Docs:

    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.