title: UITextView textViewDidChangeSelection called twice
body: <p><strong>What I have</strong>  :</p>
  
  <p>TextView</p>
  
  <p>NSArray (string)</p>
  
  <p>AVAudioplayer (not yet implemented)</p>
  
  <p><strong>When I select a word in TextView</strong> :</p>
  
  <p>• Check if word exist in Array</p>
  
  <p>• Start Audioplayer with associated sound</p>
  
  <p>Unfortunately when I tap twice to select a word inside TextView, textViewDidChangeSelection is called twice. I don’t know why I see "Youpie" twice.</p>
  
  <p>I just changed inputView to hide keyboard because I only need TextView to be used in selecting mode.</p>
  
  <pre><code>- (void)textViewDidChangeSelection:(UITextView *)tve;
  {
      NSString *selectedText = [tve textInRange:tve.selectedTextRange];
      if(selectedText.length &gt; 0)
      {
          for (NSString *text in textArray)
          {
              if ([selectedText isEqualToString:text])
              NSLog(@"Youpie");
              tve.selectedTextRange = nil;
              if (ps1.playing == YES)
              {
                  [self stopEveryPlayer];
                  [self updateViewForPlayerState:ps1];
              }
              else if ([ps1 play])
                  {
                      [self updateViewForPlayerState:ps1];
                      fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[ps1.url relativePath] lastPathComponent], ps1.numberOfChannels, nil];
                  }
                  else
                      NSLog(@"Could not play %@\n", ps1.url);
              break;
              }
          }
      }
  }
  
  - (void)awakeFromNib
  {  
      textArray = [[NSArray alloc] initWithObjects:@"dog",@"cat",@"person",@"bird",@"mouse",  nil];
      textView.inputView = [[[UIView alloc] initWithFrame:CGRectZero]  autorelease];
      textView.delegate = self;
  // ...
  }
  </code></pre>
  
  <p>I noticed something when I was double tapping on each good word in my text.</p>
  
  <p><strong>textViewDidChangeSelection</strong></p>
  
  <p>If a word is already selected and no action choosen, I have 1 "Youpie".</p>
  
  <p>If not, I have 2 "Youpie".</p>
  
  <p>I found a simple solution. I removed selectedRange after getting value. textViewDidChangeSelection called once.</p>
  
  <p><strong>What I have changed</strong></p>
  
  <pre><code>tve.selectedTextRange = nil;
  </code></pre>
  
  <p>I use a subclass of <code>UITextView</code> to disable menu.</p>
  
  <pre><code>-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
  {
      return NO;
      return [super canPerformAction:action withSender:sender];
  }
  </code></pre>
  
  <p>I added an implementation for <code>AVAudioPlayer</code> (ps1) too.</p>
  
  <p>My "autoplay" is working if a known word is selecting :)</p>