objective-c - 未调用 UITextView shouldChangeTextInRange 委托(delegate)

标签 objective-c uitextview

我正在使用这段代码来设置我 View 中的 uitextview 的参数。

_textview=[[UITextView alloc]init];
[_textview setUserInteractionEnabled:FALSE];
_textview.text=@"Write your message";
_textview.textColor=[UIColor lightGrayColor];
_textview.layer.cornerRadius=6;
_textview.contentInset = UIEdgeInsetsZero;
_textview.delegate=self;

我在 .h 中有这段代码

IBOutlet UITextView *_textview;
@property(nonatomic,retain) IBOutlet UITextView *_textview;

我已经使用接口(interface)将 outlet 连接到 uitextview。

接下来会发生什么:

- (void)textViewDidChange:(UITextView *)inTextView

调用了上面的委托(delegate),但不调用下面的委托(delegate):

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string 

为什么会这样?我做错了什么吗?

感谢任何帮助...

最佳答案

除了删除 _textview = [[UITextView alloc]init];以免覆盖您的 Nib 加载 TextView 。

<UITextViewDelegate>方法是:

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{}

正确的方法签名是:

textView:shouldChangeTextInRange:replacementText:

不是:

textView:shouldChangeTextInRange:replacementString:

关于objective-c - 未调用 UITextView shouldChangeTextInRange 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9253957/

相关文章:

objective-c - UIScrollView 中的几个 UITextField,被键盘覆盖

iphone - Calier子类问题

objective-c - 如何向 Xcode 4.3.1 中的类添加操作或导出?

ios - 使用户无法编辑 UITextView

ios - 如何停止将超链接移动到新行 UITextView

ios - 0 空间到 superview 但在 Xcode 中它们之间仍然有差距

iphone - UIButton 不更改标题

objective-c - 存储十二生肖开始和结束日期的最佳方式是什么

iOS:如何将可滚动 TextView 添加到应用程序首选项?

ios - 改变当前的 UITextView 写属性