title: iOS dismiss view controller through delegate
body: <p>I'm trying to dismiss a view controller through a delegate, but it's not responding.  </p>
  
  <p>My HomePage is the top view controller, and when a certain area of the screen is touched, the Rules view controller is pushed on top of the HomePage.  I want the HomePage view controller to dismiss the Rules view controller through the delegate </p>
  
  <p>//HomePage</p>
  
  <pre><code>@interface HomePage : UIViewController &lt;RulesControllerDelegate&gt;
  @end
  </code></pre>
  
  <p>//HomePage.m</p>
  
  <pre><code>#import "HomePage.h"
  @implementation HomePage 
  
  - (void)viewDidLoad{
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.   
  }
  
  
  -(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event{
      int offset = 30;
      UITouch *theTouch = [touches anyObject];
      CGPoint location = [theTouch locationInView:self.view];
  
      if (location.x &gt; gameLabel.frame.origin.x - offset &amp;&amp; location.y &lt; gameLabel.center.y + offset &amp;&amp; location.y &gt; gameLabel.center.y - offset) {
          NSLog(@"touched game");
      }
  
      if (location.x &lt; rulesLabel.frame.origin.x + rulesLabel.frame.size.width + offset &amp;&amp; location.y &lt; rulesLabel.center.y + offset &amp;&amp; location.y &gt; rulesLabel.center.y - offset) {
          NSLog(@"touched rules");
  
          UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Rules"];
          [self presentViewController:controller animated:YES completion:nil];
      }
  }
  
  #pragma mark - RulesControllerDelegate
  
  - (void)rulesControllerDidCancel:(Rules *)controller{
  
      [self dismissViewControllerAnimated:YES completion:nil];
  }
  
  @end
  </code></pre>
  
  <p>//Rules.h</p>
  
  <pre><code>@class Rules;
  @protocol RulesControllerDelegate &lt;NSObject&gt;
  - (void)rulesControllerDidCancel:(Rules *)controller;
  @end
  
  @interface Rules : UIViewController
  
  @property (nonatomic, weak) id &lt;RulesControllerDelegate&gt; delegate;
  
  - (IBAction)cancel:(id)sender;
  
  @end
  </code></pre>
  
  <p>//Rules.m</p>
  
  <pre><code>#import "Rules.h"
  
  @implementation Rules
  @synthesize delegate;
  
  - (IBAction)cancel:(id)sender {
      [delegate rulesControllerDidCancel:self];  //why isn't this called//////////////////////
      //[self dismissViewControllerAnimated:YES completion:nil];
  }
  
  @end
  </code></pre>