• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Opening a document in code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Strange Compiler Warning
  • Next by Date: Re: NSTextView auto scroll up behaviour
  • Previous by thread: [solved] Re: NSTextView auto scroll up behaviour
  • Next by thread: Where can I find information on making my program apple scriptable?
  • Index(es):
    • Date
    • Thread