title: OS X - How can a NSViewController find its window?
body: <p>I have a Document based core data app. The main document window has a number of views, each controlled by its own custom <code>NSViewController</code> which are switched in as necessary. I want each of these view controllers to be able to drop down a custom modal sheet from the document window. However because the views are separate and not in the <code>MyDocument</code> <code>nib</code> I cannot link the view to the document window in IB. This means that when I call</p>
  
  <pre><code>[NSApp beginSheet: sheetWindow modalForWindow: mainWindow modalDelegate: self didEndSelector: @selector(didEndSheet:returnCode:contextInfo:) contextInfo: nil];
  </code></pre>
  
  <p>I’m supplying nil for <code>mainWindow</code> and the sheet therefore appears detached.</p>
  
  <p>Any suggestions?</p>
  
  <p>Many Thanks</p>