我有一个实现UIKeyInput的视图,并覆盖shouldBecomeFirstResponder以返回YES.点击此视图时,键盘会弹出.如果用户点击听写按钮,推送完成,然后尝试解除键盘,应用程序崩溃:
Fatal Exception: NSInternalInconsistencyException NSInternalInconsistencyException
We were never set up properly to stream in this document.
我想知道是否有人知道解决这个错误的工作?我尝试实现UITextInput并将与听写相关的方法留空,这实际上是有效的.但是,当用户尝试使用Dictation并放入垃圾时,UITextInput正在访问我的insertText方法.我还没有准备好实施听写,所以我实际上只想暂时禁用它,并进行某种工作.任何输入将不胜感激!
最佳答案 实际上,实现UITextInput可以解决问题.当用户成功完成听写时,它只会向您的insertText方法发送一个空格(不完全确定如何让听写在自定义文本视图中正常工作,现在我只想修复此错误).下面我列出了您必须为UITextInput使用的所有方法和属性,以节省您的时间:
属性:
@property(nonatomic, readonly) UITextPosition *beginningOfDocument;
@property(nonatomic, readonly) UITextPosition *endOfDocument;
@property(nonatomic, assign) id<UITextInputDelegate> inputDelegate;
@property(nonatomic, readonly) UITextRange *markedTextRange;
@property(nonatomic, copy) NSDictionary *markedTextStyle;
@property(readwrite, copy) UITextRange *selectedTextRange;
@property(nonatomic, readonly) id<UITextInputTokenizer> tokenizer;
方法:
- (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction
{
return nil;
}
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return CGRectZero;
}
- (void)unmarkText
{
}
- (UITextRange *)characterRangeAtPoint:(CGPoint)point
{
return nil;
}
- (UITextRange *)characterRangeByExtendingPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction
{
return nil;
}
- (UITextPosition *)closestPositionToPoint:(CGPoint)point
{
return nil;
}
- (UITextPosition *)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange *)range
{
return nil;
}
- (NSComparisonResult)comparePosition:(UITextPosition *)position toPosition:(UITextPosition *)other
{
return nil;
}
- (void)dictationRecognitionFailed
{
}
- (void)dictationRecordingDidEnd
{
}
- (CGRect)firstRectForRange:(UITextRange *)range
{
return CGRectZero;
}
- (CGRect)frameForDictationResultPlaceholder:(id)placeholder
{
return CGRectZero;
}
- (void)insertDictationResult:(NSArray *)dictationResult
{
}
- (id)insertDictationResultPlaceholder
{
return nil;
}
- (NSInteger)offsetFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
{
return nil;
}
- (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(NSInteger)offset
{
return nil;
}
- (UITextPosition *)positionFromPosition:(UITextPosition *)position offset:(NSInteger)offset
{
return nil;
}
- (UITextPosition *)positionWithinRange:(UITextRange *)range farthestInDirection:(UITextLayoutDirection)direction
{
return nil;
}
- (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult
{
}
- (void)replaceRange:(UITextRange *)range withText:(NSString *)text
{
}
- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
return nil;
}
- (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection forRange:(UITextRange *)range
{
}
- (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange
{
}
- (NSString *)textInRange:(UITextRange *)range
{
return nil;
}
- (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
{
return nil;
}