Graphics Programs Reference
In-Depth Information
TimeViewController *tvc = [[TimeViewController alloc] init];
// same as:
TimeViewController *tvc = [[TimeViewController alloc] initWithNibName:nil
bundle:nil];
You can override initWithNibName:bundle: to perform some extra initialization
steps if you need them.
Note that the view controller's view does not appear anywhere in the view controller's
initializer. Nothing that has to do with the view happens here. We'll see why in the next
section.
UIViewController and lazy loading
When a UIViewController is instantiated, it doesn't create or load its view right
away. Only when the view is moving to the screen will a view controller bother to create
its view . By loading views only when needed, the application doesn't take up memory
that it doesn't need to.
Every UIViewController implements the method viewDidLoad that gets executed
right after it loads its view . In HypnosisViewController.m , override this method
to log a message to the console.
- (void)viewDidLoad
{
// Always call the super implementation of viewDidLoad
[super viewDidLoad];
NSLog(@"HypnosisViewController loaded its view.");
}
Then, in TimeViewController.m , override the same method.
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"TimeViewController loaded its view.");
}
Build and run the application. Notice that the console reports that HypnosisViewCon-
troller loaded its view right away. Tap on TimeViewController 's tab - the con-
sole will report that its view is now loaded. At this point, both views have been loaded,
so switching between the tabs now will no longer trigger the viewDidLoad method.
(Try it and see.)
Search WWH ::




Custom Search