NSDocument 窗口控制器和插座实例化
我的文档窗口控制器实例遇到了一个奇怪的问题。我有一个基于文档的应用程序,其中包含一个自定义窗口控制器,该控制器是从 NSDocument 主类的重写 makeWindowControllers
方法初始化的:
- (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>
我做错了什么?
I have what it seems to be a weird problem with an instance of a document window controller. I have a document-based application with a custom window controller inited from overridden makeWindowControllers
method of NSDocument main class:
- (void)makeWindowControllers
{
docWinController = [[DocumentWindowController alloc] initWithWindowNibName:@"MainDocument" owner:self];
[self addWindowController:docWinController];
}// end makeWindowControllers
The main application window contains an NSTextView object with a corresponding outlet in the file owner (the above window controller). I have an action that is called via a menu item and should set the content of the text view textStorage object.
Now, the action works as expected when the sender is, for example, a button in the window but does not work when the sender is the menu item. I expect to be an instantiation issue, but what is puzzling is that providing the following line in the action:
[[[textView textStorage] mutableString] appendFormat:@"Some text...%@\n", self];
returns two different window controller instance id's, depending on the sender (interface button or menu item). In one case (menu item), the NSLog spits:
-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x100195870>
in the other case (the button):
-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x113e72120>
What am I doing wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论