文本的编程更改未调用UITextView UITextViewTextDidChangeNotification [英] UITextView UITextViewTextDidChangeNotification not being called on programmatic change of the text

查看:207
本文介绍了文本的编程更改未调用UITextView UITextViewTextDidChangeNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义UITextView的初始化中称呼它:

I call this in the init of a custom UITextView:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textChanged:)
                                                 name:UITextViewTextDidChangeNotification
                                               object:self];

以编程方式设置textView.text = @""

关于我在做什么错的任何想法吗?

Any Ideas on what I am doing wrong?

推荐答案

您不应将self传递给最后一个参数,该参数是notificationSender,这意味着您只想观察self发送的通知

Your shouldn't pass self to the last parameter, this parameter is notificationSender, it means that you just want to observer the notifications sent by self.

观察者是这样的

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(textChanged:)
                                      name:UITextViewTextDidChangeNotification
                                      object:nil];

希望它可以提供帮助.

这篇关于文本的编程更改未调用UITextView UITextViewTextDidChangeNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆