title: textView:shouldChangeTextInRange:replacementText: returning NO, but autocorrect ignores?
body: <p>I'm having the following problem, and am not sure if this is an iOS bug, or I'm misunderstanding UITextViewDelegate callbacks. I'm able to reproduce this behavior on my device (iPad retina) and on the simulator <em>only if</em> I use the software keyboard (i.e. use my mouse to click the on-screen keyboard).</p>
  
  <p>Consider the following contrived example project <strong>(Updated 1/9/14)</strong>:
  <a href="https://www.dropbox.com/s/1q3vqfnsmmbhnuj/AutocorrectBug.zip" rel="nofollow">https://www.dropbox.com/s/1q3vqfnsmmbhnuj/AutocorrectBug.zip</a></p>
  
  <p>It's a simple UITextView, with a view controller set as its delegate, with the following delegate method:</p>
  
  <pre><code>- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  
      if ([text isEqualToString:@" "]
          &amp;&amp; range.length == 0
          &amp;&amp; (range.location == 0
              || [[textView.text substringWithRange:NSMakeRange(range.location-1, 1)] isEqualToString:@"\n"])) {
                  textView.backgroundColor = [UIColor yellowColor];
                  return NO;
      }
      return YES;
  }
  </code></pre>
  
  <p>My intention with this code is that when the user types a space <strong>(edit: and that space is the first character on the line)</strong>, the space is ignored and instead some other functionality happens, in this case the UITextView turns yellow.</p>
  
  <p>Now consider these steps:</p>
  
  <ol>
  <li>Tap in the text view to make it first responder</li>
  <li>Type "Apple", hit return and note the positioning</li>
  <li>Now, type a space (turning the text view yellow), type "Apple" again and hit return.</li>
  </ol>
  
  <p>Expected: A yellow background and text reading:</p>
  
  <pre><code>Apple
  Apple
  </code></pre>
  
  <p>Observed: A yellow background and text reading (due to an autocorrection):</p>
  
  <pre><code>Apple
   Apple
  </code></pre>
  
  <p>It appears the autocorrection logic is ignoring the result of textView:shouldChangeTextInRange:replacementText:.</p>
  
  <ul>
  <li><strong>Is this expected behavior?</strong></li>
  <li><strong>If so can it be worked around?</strong></li>
  </ul>
  
  <p><strong>Edit 1/9/14: only the first space on a line should be ignored, further spaces should be processed as normal (i.e. inserted into the text), ruling out a brute force strip of spaces. Also I'm dealing with a large string (potentially hundreds of thousands of characters) in a text editor (meaning constant user typing), so analyzing the entire string with every keystroke isn't going to be performant.</strong></p>