2012-09-04 66 views
2

我正在使用UITextView並在我的視圖控制器中添加了UITextInputDelegate。我已經實現了textDidChange和dictationRecordingDidEnd方法。 textDidChange和dictationRecordingDidEnd永遠不會被調用。請幫忙。dictationRecordingDidEnd從來沒有打電話

在MyViewController.h文件

@interface MyViewController : UIViewController <UITextViewDelegate, UITextInputDelegate> 
{ 

} 

在MyViewController.m文件

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

} 

- (void)dictationRecordingDidEnd 
{ 

} 
- (void)dictationRecognitionFailed 
{ 
    textViewResults.text = @"Dictation Failed"; 
} 
+0

您是否在MyViewController中設置了文本輸入委託給自己:viewDidLoad? – onnoweb

+1

是的,我做到了。它調用 - (void)textViewDidBeginEditing:(UITextView *)textView和 - (void)textViewDidEndEditing:(UITextView *)textView。但是從來沒有爲UITextInputDelegate調用任何委託方法(如 - (void)textDidChange:(id )textInput, - (void)dictationRecordingDidEnd, - (void)dictationRecognitionFailed)從UITextView控件建立委託鏈接到接口構建器中的File Owner委託。 –

回答

2

我不認爲你要使用的UITextInputDelegate協議使用UITextInput一個來代替。

2

我有這個相同的問題......似乎這些方法不會像他們應該調用(並且在5.1之前根本不會被調用)。我也注意到,被髮送每次輸入模式改變的通知:

UITextInputCurrentInputModeDidChangeNotification 

如果你聽爲(在NSNotificationCenter),然後調用:

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

你會得到一個NSString的當前輸入模式。遵循這個邏輯,你可以知道當它從@「聽寫」變成其他的時候,聽寫部分已經結束。 (儘管文本更改可能尚未處理,但我沒有嘗試完成)。

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

奇怪的是,UITextInputMode不是私有的,而是由方法返回的對象沒有任何公開的訪問器......(因此@selector(標識),它爲您提供了neeed字符串)。 ..不要認爲這會標誌蘋果拒絕,但買方要小心。

+0

儘管currentMode現在已被棄用,但它似乎運作良好。 Thanxx –

1

嘗試重寫dictationRecordingDidEnd方法,而不是像這樣:

#import <UIKit/UIKit.h> 

@interface MyTextField : UITextField 

@end 


#import "MyTextField.h" 

@implementation MyTextField 

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

@end 

我還沒有回來,下更早版本的操作系統進行測試,但它的iOS 8.1.1正常工作。