FROM : Greg Beaver
DATE : Mon Jan 12 17:11:19 2009
Hi,
Does anyone have working code that shows an application delegate in a
core data document-based app? I'm trying to intercept
applicationShouldOpenUntitledFile: in order to open the last-saved
document. I have code that works, but it causes this error:
*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil
some time between the setting of the delegate, which I did by inserting
this object into the nib and setting the delegate programmatically.
linking from IB did not properly set the delegate (init and
applicationDidFinishLaunching: were called, but
applicationShouldOpenUntitledFile: was never called):
@implementation GreenwoodAppDelegate
- (void) init
{
[super init];
applicationHasStarted = NO;
if (![[NSApplication sharedApplication] delegate]) {
[[NSApplication sharedApplication] setDelegate:self];
}
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
applicationHasStarted = YES;
}
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
// On startup, when asked to open an untitled file, open the last opened
// file instead
if (!applicationHasStarted)
{
// Get the recent documents
NSDocumentController *controller =
[NSDocumentController sharedDocumentController];
NSArray *documents = [controller recentDocumentURLs];
// If there is a recent document, try to open it.
if ([documents count] > 0)
{
NSError *error = nil;
[controller
openDocumentWithContentsOfURL:[documents objectAtIndex:0]
display:YES error:&error];
// If there was no error, then prevent untitled from appearing.
if (error == nil)
{
return NO;
}
}
}
return YES;
}
@end
I borrowed the code in applicationShouldOpenUntitledFile: from a helpful
blog entry, can't remember where.
Thanks,
Greg
DATE : Mon Jan 12 17:11:19 2009
Hi,
Does anyone have working code that shows an application delegate in a
core data document-based app? I'm trying to intercept
applicationShouldOpenUntitledFile: in order to open the last-saved
document. I have code that works, but it causes this error:
*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil
some time between the setting of the delegate, which I did by inserting
this object into the nib and setting the delegate programmatically.
linking from IB did not properly set the delegate (init and
applicationDidFinishLaunching: were called, but
applicationShouldOpenUntitledFile: was never called):
@implementation GreenwoodAppDelegate
- (void) init
{
[super init];
applicationHasStarted = NO;
if (![[NSApplication sharedApplication] delegate]) {
[[NSApplication sharedApplication] setDelegate:self];
}
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
applicationHasStarted = YES;
}
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
// On startup, when asked to open an untitled file, open the last opened
// file instead
if (!applicationHasStarted)
{
// Get the recent documents
NSDocumentController *controller =
[NSDocumentController sharedDocumentController];
NSArray *documents = [controller recentDocumentURLs];
// If there is a recent document, try to open it.
if ([documents count] > 0)
{
NSError *error = nil;
[controller
openDocumentWithContentsOfURL:[documents objectAtIndex:0]
display:YES error:&error];
// If there was no error, then prevent untitled from appearing.
if (error == nil)
{
return NO;
}
}
}
return YES;
}
@end
I borrowed the code in applicationShouldOpenUntitledFile: from a helpful
blog entry, can't remember where.
Thanks,
Greg
| Related mails | Author | Date |
|---|---|---|
| Greg Beaver | Jan 12, 17:11 | |
| Michael Ash | Jan 12, 17:24 | |
| Jon C. Munson II | Jan 12, 17:42 | |
| Quincey Morris | Jan 12, 19:41 | |
| Greg Beaver | Jan 12, 19:54 | |
| Keary Suska | Jan 13, 01:40 | |
| Michael Ash | Jan 13, 02:06 | |
| mmalc Crawford | Jan 13, 02:16 | |
| Quincey Morris | Jan 13, 02:47 |






Cocoa mail archive

