Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的应用程序委托中,我有一个可以由类修改的 NSString。我想做的是让另一个班级观察这个 NSString 并在这个 NSString 改变时做出反应。
有人知道我该怎么做吗?
在“其他类”上,您必须执行以下操作:
[MyAppDelegate addObserver:self forKeyPath:@"VARIABLE_NAME" options:NSKeyValueObservingOptionNew context:nil];
并实施
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;