title: How to load view in ViewController with code?
body: <p>I want to test a function of a ViewController that changes a label.text.
  At first I tried this:</p>
  
  <pre><code>ViewController* controller = [[ViewControlleralloc] initWithNibName:@"ViewController_iPhone"bundle:nil];
  [controller pressed];
  NSLog(@"%@",controller.label.text);
  </code></pre>
  
  <p>the function pressed is below:</p>
  
  <pre><code>-(void)pressed{
  self.label.text = @"hello";
  }
  </code></pre>
  
  <p>however, the result is NULL.
  Later I changed code as followed:</p>
  
  <pre><code>AppDelegate *delegate = [[UIApplicationsharedApplication] delegate];
  ViewController* controller = [[ViewControlleralloc] initWithNibName:@"ViewController_iPhone"bundle:nil];
  delegate.window.rootViewController = controller;
  [controller pressed];
  NSLog(@"%@",controller.label.text);
  </code></pre>
  
  <p>I think this code</p>
  
  <pre><code>delegate.window.rootViewController = controller;
  </code></pre>
  
  <p>can load the controller's view so that the label's text can be changed.But I don't know why.</p>