Re: Documents & Controllers
Re: Documents & Controllers
- Subject: Re: Documents & Controllers
- From: j o a r <email@hidden>
- Date: Fri, 15 Aug 2003 21:50:55 +0200
On den 15 augusti 2003, at 20:25:34PM, Seth Willits wrote:
The first problem: Instead of loading data from a file and giving it
to
the webview to display, I instead need to get an absolute url
(file:///users/seth/Desktop/myHTMLFile.html) and pass *that* to the
webview. I couldn't figure this out because I didn't see any way to
get
the file url from the NSDocument, only the file's name. So problem #1
is, how do I get the file URL?
The documenation
(<file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/Documents/index.html>) seems to suggest that you
could override these methods:
writeToFile:ofType:
writeToURL:ofType:
readFromFile:ofType:
readFromURL:ofType:
Have you tried that?
The second and more disastorous problem is, how do I give that URL to
the WebView? Currently, the address field sends an action directly to
the window controller via the File Owner in the nib file. The action
it
calls is: - (IBAction)loadURL:(NSString *)address; (I know how to
obtain the absolute path string from a NSURL so lets just assume that
somehow in someway I end up with a local url for the file I want to
open.) So the question is, how do I call that action (pretty simple to
do),
Create a public method in your window controller class that accepts an
URL/path and passes it along to it's WebView. Something like this:
- (void) loadAddress:(NSString *) adr
{
// Set new value
[myAddressTextField setStringValue: adr];
// Send action to trigger load
[myAddressTextField sendAction: [myAddressTextField action] to:
[myAddressTextField target]];
}
Then call this method from the document when it is created by "opening"
a file.
but also is it this the right way to do it? Since I have no data
that I'm manipulating (I'm just pushing thing around and the other
objects retain them for me) is it correct to have all of the code in
the FWWindowController class? Or should I have created all of my
outlets in the MyDocument class? The latter doesn't seem correct.
Use the window controller to handle the input from the user that
arrives via controls in the window. All code that relates to this goes
in the window controller. Don't put outlets in the document class, that
defeats the purpose of the window controller.
j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.