Iphone 外部类上的KVO不工作

Iphone 外部类上的KVO不工作,iphone,objective-c,ios,key-value-observing,Iphone,Objective C,Ios,Key Value Observing,我有一个带有NSString属性currentTag的MainViewController。因此,我: [self addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil]; 这样做很好,而且更改得到了正确的处理。但是,我有另一个类SecondViewController,我还希望它观察MainViewController的currentTag,因此在SecondVie

我有一个带有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];

然而,由于某些原因,这个问题没有得到处理。从来没有人打过电话。在查找代码中其他地方的问题之前,我希望确保语法和形式正确。此代码看起来正常吗?

如果您做错了,您应该执行以下操作:

[self.mainViewController addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];

你做错了,你应该:

[self.mainViewController addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];