NSDocument window controller and outlet instantiation
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]: Som开发者_开发技巧e text...<DocumentWindowController: 0x113e72120>
What am I doing wrong ?
精彩评论