use*_*452 9 xcode uilabel nsnotificationcenter ios
是否可以为UILabel的文本属性更改时设置通知?当我找不到UILabel时,我尝试了用于UITextFields的那个,但它没有用.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(posttosocial)
name:UITextFieldTextDidChangeNotification
object:nowplaying];
Run Code Online (Sandbox Code Playgroud)
小智 22
您可以使用键值观察(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. */
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5867 次 |
| 最近记录: |