Share via


UIViewController.LoadViewIfNeeded 方法

定義

如有必要,請從分鏡腳本或 NIB 同步載入 View

[Foundation.Export("loadViewIfNeeded")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public virtual void LoadViewIfNeeded ();
abstract member LoadViewIfNeeded : unit -> unit
override this.LoadViewIfNeeded : unit -> unit
屬性

備註

如果 UIViewController 具有相關聯的 Storyboard 或 NIB,這個方法可用來確保 View 物件已具現化。 (另請參閱 ViewIfLoaded)。

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

適用於

另請參閱