As part of development for my application Mac Linux USB Loader, I’ve had numerous issues with my application’s document windows not being able to be opened more than once. I can open the document (with the usual ways, and through NSDocumentController’s openDocumentWithContentsOfURL: method, but it only works once. After that, future attempts to open the same document fail. No log output or error is produced.
Through the completionHandler: parameter of the method and its associated block
parameter BOOL documentWasAlreadyOpen,I have deduced that the system believes
that the document window is still open, even though it isn’t. Here’s the
associated code:
NSDocumentController *docControl = [NSDocumentController
sharedDocumentController];
NSURL *selectedDocument = (NSURL *)[docControl recentDocumentURLs][clickedRow];
NSLog(@"Selected row %ld.", (long)clickedRow);
[docControl openDocumentWithContentsOfURL:selectedDocument display:YES
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError
*error) {
NSLog(@"Was document %@ already open? %@", [document class],
documentWasAlreadyOpen ? @"Yes" : @"No");
if (error) {
NSLog(@"Error: %@", error);
}
}];
When this code is executed to open a document, the first time the document is
opened, and it works, here’s the output (I’ve added code to my NSDocument
subclass to print some debug statements):
2013-12-31 18:37:25.844 Mac Linux USB Loader[2740:303] Selected row 0.
2013-12-31 18:37:25.848 Mac Linux USB Loader[2740:303] Created new instance of
Document. <Document: 0x600000149060>
2013-12-31 18:37:25.873 Mac Linux USB Loader[2740:303] Window controller loaded
nib. <NSWindow: 0x6080001fba00>
2013-12-31 18:37:25.938 Mac Linux USB Loader[2740:303] Was document Document
already open? No
But, after the document window has been closed with the standard close button
(i.e the red “gumdrop"), and the file is to be opened again, here’s the output:
2013-12-31 18:40:30.631 Mac Linux USB Loader[2740:303] Selected row 0.
2013-12-31 18:40:30.634 Mac Linux USB Loader[2740:303] Was document Document
already open? Yes
Here’s the window attributes of the Document window in the .xib file. Nothing
hopefully very out of order. “Release when closed” is checked, so the Document
window definitely still should not be open.
I want to emphasize that opening a new document window fails regardless of
whether it was opened using the code I provided or via the standard OS X
facilities; however, I’m posting the code because it provides the best
possibility of debugging.
Has anyone heard of this occurring before? Any help on this issue would be
greatly appreciated. I can provide any additional info that is needed to point
me in the right direction.
Happy New Year,
— SevenBits
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
