title: set Delegate to Subclass of NSImageView placed in Xib
body: <p>I have an <code>NSImageView</code> subclass that I use for dragging and dropping Files onto in my app.  </p>
  
  <p>To do this I created a subclass of <code>NSImageView</code> and also dragged the <code>NSImageView</code> onto my XIB,  I then set the class of the XIB <code>NSImageView</code> Object to my custom subclass.   </p>
  
  <p>Everything works well with the drag and drop and I know I have the correct file after the drag.  </p>
  
  <p>The problem comes in when I want to update a textfield on the MainViewController based on the file dragged in.</p>
  
  <p>I created the following subclass and protocol</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  #import &lt;Quartz/Quartz.h&gt;
  
  @protocol PDFDraggedIntoWell &lt;NSObject&gt;
  @required
  -(void)PDFDraggedIntoWellWithURL:(NSURL*) importedURL;
  
  @end
  
  
  @interface DragAndDropImageView : NSImageView
  
  @property (strong) id &lt;PDFDraggedIntoWell&gt; delegate;
  
  @end
  </code></pre>
  
  <p>Then in my implementation in the subclass I try to call the delegate method</p>
  
  <pre><code>-(void) finishedDragginInFileWithURL:(NSURL*) importedURL{
      if( self.delegate != nil &amp;&amp; [ self.delegate respondsToSelector: @selector(PDFDraggedIntoWellWithURL:)]) {
          [self.delegate performSelector:@selector(PDFDraggedIntoWellWithURL:) withObject:importedURL];
      }
  }
  </code></pre>
  
  <p>The problem I run into is how do you assign the delegate.  From the XIB NSImageView to my MainviewController I connect up an <code>IBOutlet</code></p>
  
  <pre><code>@property (weak) IBOutlet DragAndDropImageView *draggedFileImageView;
  </code></pre>
  
  <p>And I have declared that my ViewController will receive the delegate</p>
  
  <pre><code>@interface MyMainUIViewController ()&lt;PDFDraggedIntoWell&gt;
  </code></pre>
  
  <p>with the appropriate method implemented</p>
  
  <pre><code>-(void) PDFDraggedIntoWellWithURL:(NSURL *)importedURL{   }
  </code></pre>
  
  <p>Now I have tried in various places to assign delegate to self (in <code>viewDidLoad</code> - which doesn’t get called since the view is being loaded in a XIB??) and also in </p>
  
  <pre><code>- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  </code></pre>
  
  <p>but all I get back is the delegate is still nil when debugging.  </p>
  
  <p>What am I doing wrong? Thanks for the help!!</p>