Re: Mutable/non-mutable bindings in NSTextView
Re: Mutable/non-mutable bindings in NSTextView
- Subject: Re: Mutable/non-mutable bindings in NSTextView
- From: David <email@hidden>
- Date: Sat, 25 Feb 2006 10:22:24 -0600
On Feb 25, 2006, at 1:05 AM, Greg Herlihy wrote:
On 2/24/06 7:24 PM, "David" <email@hidden> wrote:
This would appear to be a simple problem but for some reason can't
get it to work.
I am binding to the VALUE of an NSTextView which gives me an NSString
in my model class. When a user clicks on a button I wish to clear
the contents of the NSTextView. The value binding of NSTextView is a
non-mutable string so how do I clear it? Releasing and setting the
NSString to empty string is not enough.
The program can either call setString:@"" on the NSTextView itself or
setValue:forKey: on the bound model object, specifying an empty
string and
the name of the bound property. Calling setValue:forKey ensures
that the
change is made in a key-value observing (KVO) compliant manner and
that the
value of the NSTextView is properly updated.
Yes, I missed that key step. Thanks. I've found that I can also
use willChangeValueForKey and didChangeValueForKey then do the
regular release and new allocation.
Since I will be continuously updating the NSTextView contents
programmatically as well, it appears I will have to do something like:
[self willChangeValueForKey:@"log"];
NSString *newLogContents = [[log stringByAppendingString:@"more
contents added"] retain];
[log release];
log = newLogContents;
[self didChangeValueForKey:@"log"];
Is this correct approach?
_______________________________________________
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