[self.label addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
- (IBAction)click:(id)sender {
self.label.text = @"hh";
NSString *str = [self.m valueForKeyPath:@"label.text"];
NSLog(@"%@",str);
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
}
- (void)dealloc {
[self.label removeObserver:self forKeyPath:@"text"];
}
KVC与KVO的用法
最新推荐文章于 2023-05-14 12:18:38 发布