您的位置:首页 > 其它

监听textView的属性的改变,用通知,代理不好用

2015-10-26 11:22 369 查看
添加通知

/**
*  添加textView
*/
- (void)setupTextView
{
// 1.添加
IWTextView *textView = [[IWTextView alloc] init];
textView.font = [UIFont systemFontOfSize:15];
textView.frame = self.view.bounds;
[self.view addSubview:textView];
self.textView = textView;

// 2.监听textView文字改变的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:textView];
}


移除通知

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}


监听文字改变,当不输入文字时,发微博的按钮是灰色的,当输入文字的时候按钮是橙色的。

/**
*  监听文字改变
*/
- (void)textDidChange
{
self.navigationItem.rightBarButtonItem.enabled = (self.textView.text.length != 0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: