In the application I'm currently working on, there's a case where I have 2 screens for a set of data: one is a list and one is a map. Each screen has its own view controller. The default screen is the list view, so that view controller loads first. But the other map screen view controller is also loaded and set up (as it encapsulates some geographic map-related data that the list screen view controller uses), even though the map screen is not visible yet.
I don't want the map screen view controller's nib and views to be loaded and initialized until the user switches to that screen, however.
Is there anything wrong with overriding the view
property accessor within the map screen view controller as in the code below, and lazily loading/instantiating the nib? (The view
property is not accessed until the map screen is about to be displayed, right before the map screen view controller's viewDidLoad
method gets called.) I've tested that this works well, but I've never seen it done this way.
- (UIView *)view {
if (!_view) {
UINib *nib = [UINib nibWithNibName:@"MyNibName" bundle:nil];
[nib instantiateWithOwner:self options:nil];
}
return _view;
}