我希望有人可以帮助解决我的通知问题。我有一个通知,看起来设置正确,但未按预期发送。我正在开发一个基于文档的应用程序。委托/文档类在从保存的文件中读取时发布通知:
[[NSNotificationCenter defaultCenter] postNotificationName:notifyBsplinePolyOpened object:self];
日志记录告诉我,每当我打开保存的文档时都会到达这一行。
在 DrawView 类中,我有 windowOpen 通知和 bsplinePoly 文件打开通知的观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(mainWindowOpen:)
name:NSWindowDidBecomeMainNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(savedBspline:)
name:notifyBsplinePolyOpened
object:nil];
- (void) mainWindowOpen:(NSNotification*) note
{
NSLog(@"Window opened");
_mainWindow = [note object];
}
- (void) savedBspline:(NSNotification*) note
{
NSLog(@"savedBspline called");
NSLog(@"note is %@", [note name]);
}
行为很奇怪。当我保存并关闭主窗口并重新打开它时,我收到“窗口已打开”消息,但没有收到“已保存的样条调用”消息。如果我让主窗口保持打开状态并打开之前保存的会话,我会收到“窗口已打开”消息和“已调用保存的样条线”消息。
我搜索了在线讨论和 Apple DevCenter 文档,但我没有看到这个问题。