Opening a document in code
Opening a document in code
- Subject: Opening a document in code
- From: John Nairn <email@hidden>
- Date: Tue, 30 Aug 2005 21:08:27 -0600
I am trying to open a document in code (rather then the Open menu
command). I have code that worked after a menu command, but when it
is called after clicking on a button in a panel window it crashes. I
determined the file opens, all data is read, my windowDidLoad method
is called and succeeds, but it then crashes before ever returning
from the openDocumentWithContentsOfURL. Below are action methods of
the button and code to open the document
- (IBAction)openProcess:(id)sender
{
NSString *sourceFile=[inputPathText stringValue];
NSString *msg=[ResultsDocument openResultsFile:sourceFile];
if(msg!=nil)
{ NSBeginInformationalAlertSheet(@"The background process
results could not be opened.",
@"OK",nil,nil,[self window],self,nil,nil,nil,msg);
}
}
+ (NSString *)openResultsFile:(NSString *)sourceFile
{
// if that document is open, close it first
ResultsDocument *resDoc;
NSURL *sourceURL=[NSURL fileURLWithPath:sourceFile];
if(resDoc=[[NSDocumentController sharedDocumentController]
documentForURL:sourceURL])
{ [resDoc close];
}
// now open it
NSError *outError;
if(resDoc=[[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:sourceURL display:YES
error:&outError])
{ return [outError localizedDescription];
}
return nil;
}
---------------
John Nairn (1-801-581-3413, FAX:1-801-581-4816)
Web Page: http://www.mse.utah.edu/~nairn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden