我有一个文档窗口控制器的实例似乎是一个奇怪的问题。我有一个基于文档的应用程序,它具有从makeWindowControllers
NSDocument 主类的重写方法初始化的自定义窗口控制器:
- (void)makeWindowControllers
{
docWinController = [[DocumentWindowController alloc] initWithWindowNibName:@"MainDocument" owner:self];
[self addWindowController:docWinController];
}// end makeWindowControllers
主应用程序窗口包含一个 NSTextView 对象,该对象在文件所有者(上述窗口控制器)中具有相应的出口。我有一个通过菜单项调用的操作,应该设置文本视图 textStorage 对象的内容。
现在,当发送者是窗口中的按钮时,该操作按预期工作,但当发送者是菜单项时,该操作不起作用。我希望这是一个实例化问题,但令人费解的是在操作中提供以下行:
[[[textView textStorage] mutableString] appendFormat:@"Some text...%@\n", self];
根据发送者(界面按钮或菜单项)返回两个不同的窗口控制器实例 ID。在一种情况下(菜单项),NSLog 吐出:
-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x100195870>
在另一种情况下(按钮):
-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x113e72120>
我究竟做错了什么 ?