gpt4 book ai didi

ios - 更改 UITextView.inputView 时不调用 textViewDidChange?

转载 作者:可可西里 更新时间:2023-11-01 06:25:00 25 4
gpt4 key购买 nike

我拖动一个 UITextView 并将委托(delegate)与 File's Owner Hook 。
textViewDidChange 仅使用默认键盘调用,但从我的键盘输入文本时没有任何反应。

如何在将 inputView 设置为自定义键盘时启用 UITextView 的委托(delegate)?

这是我的代码

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);
}

我的键盘.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];
}

最佳答案

在您的自定义键盘中,您可能会使用方法 setText: 更改 textView 中的文本,但在此方法中所做的更改不会调用 textViewDidChanged回调。
documentation 中阅读更多内容.

textViewDidChange:
Discussion

The text view calls this method in response to user-initiated changes to the text. This method is not called in response to programmatically initiated changes.

因此,您应该从键盘手动调用此方法。

关于ios - 更改 UITextView.inputView 时不调用 textViewDidChange?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16115344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com