当UILabel的文本属性更改时,是否可以设置通知?当我找不到UILabel的UITextFields时,我尝试了一个UITextField,但是它没有起作用.
[[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(posttosocial) name:UITextFieldTextDidChangeNotification object:Nowplaying];
解决方法
您可以使用键值观察(KVO):
[label addobserver:self
forKeyPath:@"text"
options:NSkeyvalueObservingOptionNew
| NSkeyvalueObservingOptionOld
context:NULL];
- (void)observeValueForKeyPath:(Nsstring *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"text"]) {
/* etc. */
}
}