Create and save a NSPersistentDocument from scratch
Create and save a NSPersistentDocument from scratch
- Subject: Create and save a NSPersistentDocument from scratch
- From: Eric Morand <email@hidden>
- Date: Wed, 11 Nov 2009 13:34:46 +0100
Hi guys !
I'm trying to implement a "welcome screen" like the ones found in Garage Band or Xcode : the user will be showed a window with a "Create new document" button that, when clicked, show a save panel. Once saved, the application should open the document.
I'm facing a problem when I try to save the newly created document on the disk : the application raise an error ('The document 'MyDoc' could not be saved").
Here is the code I use to show the save panel and save the document to the disk :
- (IBAction)createNewDocument:(id)sender {
NSSavePanel * savePanel = [NSSavePanel savePanel];
[savePanel beginSheetForDirectory:nil
file:NSLocalizedString(@"MyDoc", @"")
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSOKButton) {
NSPersistentDocument * newDoc = [[[NSPersistentDocument alloc] init] autorelease];
[newDoc setFileType:@"SQLite"];
[newDoc setFileURL:[sheet URL]];
[newDoc saveDocument:self];
}
[sheet orderOut:self];
}
Can someone help me on this ?
Thanks by advance,
Eric.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden