我拖动一个UITextView
并将委托与File's Owner
.
仅使用textViewDidChange
默认键盘调用,但从我的键盘输入文本时没有任何反应。
如何UITextView
在将其设置inputView
为自定义键盘时启用委托?
这是我的代码
视图控制器.m
-(void)viewDidLoad{
self.myKeyboard = [[[NSBundle mainBundle] loadNibNamed:@"MyKeyboard" owner:nil options:nil] objectAtIndex:0];
[self.myKeyboard setTextView:self.textView];
}
#pragma mark TestViewDelegate
- (void)textViewDidChange:(UITextView *)textView{
NSLog(@"TextDidChange: %@",textView.text);
}
我的键盘.h
@interface MyKeyboard : UIView
@property (weak,nonatomic) id<UITextInput> textView;
-(void)setTextView:(id<UITextInput>)textView;
@end
我的键盘.m
-(void)setTextView:(id<UITextInput>)textView{
_textView = textView;
if ([textView isKindOfClass:[UITextView class]])
[(UITextView *)textView setInputView:self];
else if ([textView isKindOfClass:[UITextField class]])
[(UITextField *)textView setInputView:self];
}