 |
 |
Best way to clear contents of NSTextView?
|
 |
|
 |
|
Senior User
Join Date: Jan 2000
Status:
Offline
|
|
I'm working on a small app (for the sake of learning Obj-C) that uses an NSTextView. When the user clicks on the lone button available, some things are written to the NSTextView.
I'd like to delete the original contents of the text field every time the button is clicked, replacing them with the new contents. As it stands now, the new text is merely appended to the old.
Any suggestions? At the moment, I'm using insertText: to add text to the NSTextView.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Use [yourTextView setString:""];
Atleast i think that's what it was...
HTH,
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
Originally posted by Ghoser777:
<STRONG>Use [yourTextView setString:""];
</STRONG>
<font face = "courier">
shouldn't that be [yourTextView setString:@""];
</font>
...?
[edit: my way of marking the change didn't work, note the "@" behind the colon]
[ 10-25-2001: Message edited by: seb2 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Bah, I'm a java guy learning Obj-C, we forget @'s every once in a while
Sorry,
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2000
Status:
Offline
|
|
Thanks much to you both. That's what I was looking for.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status:
Offline
|
|
Forgetting the @ is pretty bad. It just produces a warning at compile time, but it's a bad crash (SIGBUS) at runtime. I already spend HOURS by looking for a memory problem in my app when all I did wrong was to forget an @.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Same here; It took me forever to figure out why all these @'s where in Objective-C code. String objects in Java are so much easier (and so much more intuitive for that matter).
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status:
Offline
|
|
Originally posted by Ghoser777:
<STRONG>Same here; It took me forever to figure out why all these @'s where in Objective-C code. String objects in Java are so much easier (and so much more intuitive for that matter).
F-bacher</STRONG>
You can always avoid the "@" notation if it annoys you. Just use
[yourTextView setString:[[NSString alloc] initWithCString:""]];
[ 10-26-2001: Message edited by: TheBum ]
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Actually, that's a memory leak. You'd need:
[yourTextView setString:[NSString stringWithCString:""]];
or just
[yourTextView setString:[NSString string]];
but of course the @"" is easiest and best.
Since Objective-C is an extension of ANSI C, regular old "" still has to mean constant c-strings, so ObjC has to use @"" to represent constant NSString objects. Slightly annoying, but you can get used to it. Just don't ever ignore those compiler warnings :-)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Well, @"" is nice when you compare it to CFSTR(""), which is how you declare constant CFStrings 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|