I drag a UITextView
and hook up delegate with File's Owner
.
The textViewDidChange
is called only with default keyboard, but nothing happen when input text from my keyboard.
How to enable delegate of UITextView
when set its inputView
to a custom keyboard?
Here is my code
ViewController.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);
}
MyKeyboard.h
@interface MyKeyboard : UIView
@property (weak,nonatomic) id<UITextInput> textView;
-(void)setTextView:(id<UITextInput>)textView;
@end
MyKeyboard.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];
}
textView.delegate = self
? – Shadchan