我有一个带有 NSString 属性 currentTag 的 MainViewController。所以我这样做:
[self addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];
这很好用,并且更改确实得到了正确处理。但是,我有另一个类SecondViewController,我也想让它观察MainViewController的currentTag,所以在SecondViewController的viewDidLoad方法中,我这样做:
[self addObserver:self.mainViewController forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];
但是,由于某种原因,这个没有得到处理。它永远不会被调用。我想确保我的语法和形式是正确的,然后再在我的代码中寻找问题的其他地方。这段代码看起来没问题吗?