2

I am using a UITextView and added UITextInputDelegate in my view controller. I have implemented textDidChange and dictationRecordingDidEnd methods. The textDidChange and dictationRecordingDidEnd are never called. Please help.

In MyViewController.h file

@interface MyViewController : UIViewController <UITextViewDelegate, UITextInputDelegate>
{

}

In MyViewController.m file

- (void) textDidChange:(id<UITextInput>)textInput
{

}

- (void)dictationRecordingDidEnd
{

}
- (void)dictationRecognitionFailed
{
    textViewResults.text = @"Dictation Failed";
}
Ram G.
  • 3,045
  • 2
  • 25
  • 31
  • Did you set text input delegate to self in MyViewController:viewDidLoad? – onnoweb Sep 04 '12 at 18:17
  • 1
    Yes, I did. It calls - (void)textViewDidBeginEditing:(UITextView *)textView and - (void)textViewDidEndEditing:(UITextView *)textView. But never calls any delegate methods for UITextInputDelegate (like - (void) textDidChange:(id)textInput, - (void)dictationRecordingDidEnd, - (void)dictationRecognitionFailed) the delegate link is established from UITextView control to File Owner delegate in interface builder. – Ram G. Sep 05 '12 at 16:11

3 Answers3

2

I dont think you want to use the UITextInputDelegate protocol use the UITextInput one instead.

cynistersix
  • 1,215
  • 1
  • 16
  • 30
2

I had this same problem... seems that the methods don't get called like they should (and don't get called at all prior to 5.1). I did notice a notification that gets sent every time the input mode changes:

UITextInputCurrentInputModeDidChangeNotification

If you listen for that (in NSNotificationCenter) and then call:

[[UITextInputMode currentMode] performSelector:@selector(identifier)];

You'll get an NSString for the current input mode. Following that logic you can know that when it changes from @"dictate" to something else, then the dictation part has ended. (though the text change may not be processed yet, I haven't tried that all the way out).

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInputMode_Class/Reference/Reference.html

Strangely, UITextInputMode is not private, but the objects returned by the methods don't have any public accessors... (thus the @selector(identifier) which gives you the string you neeed)... Don't think this will flag for Apple rejection but buyer beware.

BadPirate
  • 25,802
  • 10
  • 92
  • 123
1

Try overriding the dictationRecordingDidEnd method, instead, like this:

#import <UIKit/UIKit.h>

@interface MyTextField : UITextField

@end


#import "MyTextField.h"

@implementation MyTextField

- (void) dictationRecordingDidEnd {
    printf("dictationRecordingDidEnd\n");
}

@end

I have not gone back and tested under earlier operating systems, but it works fine in iOS 8.1.1.

Mike
  • 3,084
  • 1
  • 25
  • 44