title: Implementing delegate methods for modal view controller data transfer
body: <p>I have a simple project to present a modal view controller and transfer back a string based on which button in the modal VC that gets pressed.  I based it all on watching the Stanford class on iTunes U.  It looks like I have everything correct, but I get a couple of compiler warnings.</p>
  
  <p>First I get one called <code>passing argument 1 of 'setDelegate:' from incompatible pointer type</code> in <code>TransferViewController.m</code></p>
  
  <p>Second I get four warnings called <code>Invalid receiver type 'id &lt;MyModalViewControllerDelegate&gt;*'</code> but these aren't displayed in the build results area, rather next to the offending lines in <code>MyModalViewController.m</code>, both lines in each of the button actions.</p>
  
  <p>Here's the code...</p>
  
  <pre><code>//  TransferViewController.h
  
  #import &lt;UIKit/UIKit.h&gt;
  #import "MyModalViewController.h";
  
  @interface TransferViewController : UIViewController &lt;MyModalViewControllerDelegate&gt; {
      UILabel *label;
      UIButton *button;
  }
  
  @property (nonatomic, retain) IBOutlet UILabel *label;
  @property (nonatomic, retain) UIButton *button;
  
  - (IBAction)updateText;
  
  @end
  </code></pre>
  
  <hr>
  
  <pre><code>//  TransferViewController.m
  
  #import "TransferViewController.h"
  
  @implementation TransferViewController
  
  @synthesize label;
  @synthesize button;
  
  - (IBAction)updateText {
      MyModalViewController *myModalViewController = [[MyModalViewController alloc] init];
      myModalViewController.delegate = self; // I get the warning here.
      [self presentModalViewController:myModalViewController animated:YES];
      [myModalViewController release];
  }
  
  - (void)myModalViewController:(MyModalViewController *)controller didFinishSelecting:(NSString *)selectedDog {
      label.text = selectedDog;
      [self dismissModalViewControllerAnimated:YES];
  }
  
  @end
  </code></pre>
  
  <hr>
  
  <pre><code>//  MyModalViewController.h
  
  #import &lt;UIKit/UIKit.h&gt;
  
  @protocol MyModalViewControllerDelegate;
  
  @interface MyModalViewController : UIViewController {
      UIButton *abby;
      UIButton *zion;
      id &lt;MyModalViewControllerDelegate&gt; delegate;
  }
  
  @property (assign) id &lt;MyModalViewControllerDelegate&gt; delegate;
  
  - (IBAction)selectedAbby;
  - (IBAction)selectedZion;
  
  @end
  
  @protocol MyModalViewControllerDelegate &lt;NSObject&gt;
  
  @optional
  
  - (void)myModalViewController:(MyModalViewController *)controller didFinishSelecting:(NSString *)selectedDog;
  
  @end
  </code></pre>
  
  <hr>
  
  <pre><code>//  MyModalViewController.m
  
  #import "MyModalViewController.h"
  
  @implementation MyModalViewController
  
  @synthesize delegate;
  
  - (IBAction)selectedAbby {
      if ([self.delegate respondsToSelector:@selector (myModalViewController:didFinishSelecting:)]) {
          [self.delegate myModalViewController:self didFinishSelecting:@"Abby"];
      }
  }
  
  - (IBAction)selectedZion {
      if ([self.delegate respondsToSelector:@selector (myModalViewController:didFinishSelecting:)]) {
          [self.delegate myModalViewController:self didFinishSelecting:@"Zion"];
      }
  
  }
  </code></pre>