loadView
is expected to, at some point, populate the view
property of a view controller. The view property is lazily loaded (look at the call stack, you will see a method called something like _loadViewIfNeeded
).
If loadView
doesn't create a view, then each time the .view
property is accessed, the view controller will call loadView
again, trying to lazily load the view. At some point everything will go wrong because a view controller needs a view. If you access self.view from within your custom loadView, you'll get an infinite loop.
From the documentation:
You can override this method in order to create your views manually. If you choose to do so, assign the root view of your view hierarchy to the view property. The views you create should be unique instances and should not be shared with any other view controller object. Your custom implementation of this method should not call super.