Fwd: Re: Newbie Question about Document/Window/Text Field
Fwd: Re: Newbie Question about Document/Window/Text Field
- Subject: Fwd: Re: Newbie Question about Document/Window/Text Field
- From: Deirdre Saoirse Moen <email@hidden>
- Date: Tue, 15 May 2001 13:13:27 -0700
Gah, it was really too late -- I sent this post to the admin instead
of the list.
I am trying to create a simple text-editor in my quest to learn
Cocoa, so I've created a project with the document-based app
template and added a big scrolling text field to the window. Bingo!
I have a working text editor. Gotta love that ;)
Yeah, I know -- isn't that part great?
Unfortunately, none of the doc with read/write samples are simple
enough to really show off the structure, which is why I was working
on my complaint example -- a small NSTextField to enter one's
complaint into, etc.
Now I want to implement saving, so my question is: how do I get the
text that's in the text view when I get asked to save my document?
I have saving and I have re-reading, but thus far my little app isn't
displaying correctly, so I'm reading my mail before going to sleep. I
suspect sleep will cause a "doh!" moment. :)
Where in the documentation can I find answers to such basic questions?
Not, but see below. This was in my NSDocument subclass. docText is an
NSString * and complaint is the id that comes from the NSTextField
(in my case).
- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType
{
docText = [complaint stringValue];
[docText writeToFile:fileName atomically:NO];
return YES;
}
Hard to believe you've stressed that much over three lines of code,
isn't it? :)
What I've got for reading in:
- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType
{
docText = [NSString stringWithContentsOfFile:fileName];
if (docText != nil)
{
[complaint setStringValue:docText];
}
return (docText != nil);
}
But the setStringValue isn't.
Again, right now, I'm not worrying too much (given that I'm writing
teensy files) about the finer points of memory management.
--
_Deirdre Stash-o-Matic:
http://weirdre.com http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
- Douglas Adams