UIViewController.ViewIfLoaded Property


Returns the View if it has been instantiated; otherwise, returns null.

[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[get: ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[get: Foundation.Export("viewIfLoaded", ObjCRuntime.ArgumentSemantic.Strong)]
public virtual UIKit.UIView ViewIfLoaded { get; }
member this.ViewIfLoaded : UIKit.UIView

Property Value


A null return indicates that the View has not yet been loaded.

This value can be null.



Because UIView are relatively heavyweight compared to TUIViewController objects, the View object is lazily initialized. Developers can test if the View has been initialized by calling this method, which returns null if the View had not yet been loaded. Developers can call LoadViewIfNeeded() to force the loading of the View.

var newVC = UIStoryboard.FromName("Main", NSBundle.MainBundle).InstantiateInitialViewController();
if (newVC.ViewIfLoaded == null)
    //This call blocks until the View is instantiated

Applies to