ios_KVO 基本用法 代码

来源:互联网 发布:淘宝客服能学到东西吗 编辑:程序博客网 时间:2024/04/20 14:05

@interface ViewController ()@property(copy,nonatomic)NSString *str;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    self.str = @"1";    [self addObserver:self forKeyPath:@"str" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];}- (IBAction)ss:(id)sender {    self.str = @"2";}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{    NSLog(@"%@,%@",keyPath,change);}

举一反三

0 0
原创粉丝点击