title: iOS6 bug in UITapGestureRecognizer gestureRecognizer:shouldReceiveTouch:?
body: <p>The following code in my view controller results in an <code>EXC_BAD_ACCESS</code> at the <code>touch.view</code> call:</p>
  
  <pre><code>- (BOOL)handleSingleTap:(UITapGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
  
      if ([touch.view isKindOfClass:[UIControl class]]) {   // &lt;&lt;&lt;&lt; EXC_BAD_ACCESS HERE
          // we touched a button, slider, or other UIControl
          return NO; // ignore the touch
      }
      [self.view endEditing:YES];  // dismiss the keyboard
      return YES; // handle the touch    
  }
  </code></pre>
  
  <p><code>touch</code> appears to be a zombie.  Specifically, <code>touch</code> is set to an address, and the debugger thinks that's a <code>UITouch</code> pointer, but it doesn't have any properties:</p>
  
  <p><img src="https://i.stack.imgur.com/Y21rB.png" alt="as can be seen in the debugger"></p>
  
  <p>This did not happen in iOS 4.x.  So iOS 6 bug or my fault?</p>
  
  <p>The gesture recognizer is set up as follows (in the ViewController):</p>
  
  <pre><code>UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:shouldReceiveTouch:)];
  [tapRecognizer setDelegate:self];
  [tapRecognizer setNumberOfTapsRequired:1];
  [tapRecognizer setNumberOfTouchesRequired:1];
  tapRecognizer.cancelsTouchesInView = NO;
  [self.view addGestureRecognizer:tapRecognizer];
  [tapRecognizer release];
  </code></pre>
  
  <p><strong>UPDATE/SOLUTION:</strong></p>
  
  <p>Thanks to Rob for pointing out the user error on my part.  Not only that, but I don't actually need the TapRecognizer since I just want to know a touch happened.</p>
  
  <p>Here's the correct code to dismiss the on-screen keyboard with a touch anywhere but in a UIControl:</p>
  
  <p>In the ViewController's <code>viewDidLoad</code>:</p>
  
  <pre><code>UIGestureRecognizer *myRecognizer = [[UIGestureRecognizer alloc] init];
  [myRecognizer setDelegate:self];
  myRecognizer.cancelsTouchesInView = NO;
  [self.view addGestureRecognizer:myRecognizer];
  [myRecognizer release];
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch  {
  
  if ([touch.view isKindOfClass:[UIControl class]]) {
      // we touched a button, slider, or other UIControl
      return NO; // ignore the touch
  }
  
  [self.view endEditing:YES];  // dismiss the keyboard
  return YES; // handle the touch    
  </code></pre>
  
  <p>}</p>