title: Defining delegate function in separate file (instead of in ViewController)
body: <p>I have a ViewController, and a UIView.
  The UIView has a delegate, and the delegate function is set in the ViewController.</p>
  
  <p><strong>All I want to do, is have the delegate function defined in a separate file.</strong> So the UIView.m #imports the separate file, instead of all the ViewControllers which use the UIView.</p>
  
  <p>I believe this is a standard procedure, but keep falling over myself trying to get it to work. :| Would really appreciate some help. Thanks.</p>
  
  <p><strong>myViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "myUIView.h"
  @protocol ModalViewDelegate                     
  -(void)didReceiveMessage:(NSString *)message;   
  @end
  @interface myViewController : UIViewController &lt;ModalViewDelegate&gt;
  @property (nonatomic, strong) myUIView *myUIViewItem;
  @end
  </code></pre>
  
  <p><strong>myViewController.m</strong></p>
  
  <pre><code>#import "myViewController.h"
  #import "myUIView.h"
  @interface myViewController ()
  @end
  @implementation myViewController
  
  @synthesize myUIViewItem;
  - (void)didReceiveMessage:(NSString *)message { //&lt;&lt;&lt; THIS IS WHAT
      NSLog(@"Message from button: %@", message); //&lt;&lt;&lt; NEEDS MOVING
  }
  - (void)viewDidLoad
  {
  …
  myUIViewItem.delegate = self;
  …
  </code></pre>
  
  <p><strong>myUIView.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @protocol ModalViewDelegate;
  @interface myUIView : UIView {
      id&lt;ModalViewDelegate&gt; delegate;
  }
  @property (nonatomic, strong) id&lt;ModalViewDelegate&gt; delegate;
  </code></pre>
  
  <p><strong>myUIView.m</strong></p>
  
  <pre><code>#import "myUIView.h"
  #import "myViewController.h"
  @implementation myUIView
  @synthesize delegate;
  ...
  [delegate didReceiveMessage:@"Data from UIView!"];
  </code></pre>