title: Programmatically creating new windows and accessing window objects in Cocoa
body: <p>I'm having an issue with creating new windows in Cocoa.
  Hypothetically speaking, let's say I have "WindowA" and has a button called "myButton".
  When you click on "myButton", it runs this code in the following class file:</p>
  
  <pre><code> -(void)openFile2:(id)sender
  {
      myNextWindow = [[TestWindowController alloc] initWithWindowNibName:@"MainMenu"];
      NSString *testString = @"foo";
  
      [myNextWindow showWindow:self];
      [myNextWindow setButtonText:testString];
  }
  </code></pre>
  
  <p>The code in a nutshell makes a duplicate "WindowA" and shows it. As you can see, this code also runs a method called 'setButtonText', which is this:</p>
  
  <pre><code>- (void)setButtonText:(NSString *)passedText
  {
      [myButton setTitle:passedText];
  }
  </code></pre>
  
  <p>The problem is that when I call this method locally, in the original window - the button text changes (e.g., [self setButtonText:testString]) it works.  However, it does not work in the newly created window (e.g., [myNextWindow setButtonText:testString];)</p>
  
  <p>When I debug the newly created window, step by step, the 'myButton' value it gives is 0x0.  Do I have to manually assign controllers/delegates to the new window?  I think the 'myButton' in the code isn't associated to the 'myButton' in the newly created window.</p>
  
  <p>How would I fix this problem?</p>