I have been working on this now for a few days and haven't had any luck. I have a text to speech app and I need to trigger a method in my code every time the user taps on the spacebar. So they will be typing and after every word they tap the spacebar and the app will do something. I found a few examples here that seem to be similar, but I haven't gotten them to work. I have implemented the code suggested, as you can see below, but I do not receive any response. Here is what I have tried.
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if([self.myTextView.text isEqualToString:@" "]) {
/* do something */
NSLog(@"YES YES YES");
}
return YES;
}
I also tried setting up a notification center alert as follows:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textViewText:)
name:UITextViewTextDidChangeNotification
object:self.myTextView];
- (void)textViewText:(NSNotification *)notification {
if([self.myTextView.text isEqualToString:@" "]) {
/* do something */
NSLog(@"YES YES YES");
}
}
Neither of these trigger the NSLog. This is what I basically need to do:
if(the user taps the spacebar) {
[self trigger the play method];
}
Any help will be greatly appreciated. If it makes a difference, my app is 100% free, has no ads and is used by a lot of people with ALS and other diseases and have lost their ability to speak.