Reputation: 16544
I have an NSDocumentController subclass and I'm overriding the -newDocument: method.
How do I create a new document with a title? This is the short version of what I have which works but the document first shows with "Untitled" and then changes to my custom title. I would like the new document to open up immediately with the custom title.
MyDocument *document = (MyDocument *)[self openUntitledDocumentAndDisplay:YES error:&error];
[document setDisplayName:@"My Title"];
I tried this but it doesn't work for me. The document doesn't show up.
MyDocument *document = (MyDocument *)[self openUntitledDocumentAndDisplay:NO error:&error];
[document setDisplayName:@"My Title"];
[document showWindows];
Upvotes: 1
Views: 1060
Reputation: 7084
You are missing the step where you make the window controllers associated with the document.
[document showWindows];
only shows the windows already associated with the document.
You need to send the document -makeWindowControllers
, or make them yourself, as appropriate, and send the document -addWindowController:
before sending it -showWindows
.
Upvotes: 2