UIViewController.View.Window is null in ViewDidLoad method

cheesus picture cheesus · Apr 23, 2012 · Viewed 9.2k times · Source

Regardless on which controller type (UIViewController, UITableViewController), the following line always yields null in the ViewDidLoad method:

this.View.Window

Is this behavior normal, or am I doing something odd? What could lead to UIViewController.View.Window being null?

(I suppose this question concerns not only MonoTouch, but also 'normal' Objective-C Cocoa).

(MonoTouch 5.2.11, Xcode 4.2.1 4D502)

Answer

sch picture sch · Apr 23, 2012

According to the documentation of UIView, the window property is nil if the view has not yet been added to a window which is the case when viewDidLoad is called.