Re: NSMutableAttributedString binding
Re: NSMutableAttributedString binding
- Subject: Re: NSMutableAttributedString binding
- From: Ivan C Myrvold <email@hidden>
- Date: Thu, 10 Jan 2008 20:28:14 +0100
Den 10. jan.. 2008 kl. 18:28 skrev Douglas Davidson:
On Jan 10, 2008, at 9:11 AM, Ivan C Myrvold wrote:
I have binded the a NSTextView to an NSAttributedString. This works
fine when I set the binded variable, the NSTextView is showing the
text fine.
But if I make a change in the variable, this is not reflected in
the NSTextView.
I am doing this:
[[self attributedText] replaceCharactersInRange:elementRange
withString:[te c]];
and the NSTextView which is binded to attributedText does never
show the change.
If I do an NSLog of this variable immediately following the above
line, I can see the change.
What should I do to get the NSTextView to show the change?
This isn't a case for bindings, it's a case for using the text
system. Each NSTextView already has a mutable attributed string,
its text storage, and it listens for changes to the text storage
automatically. What you are doing is maintaining two separate
copies of the text, and trying to have the text entirely copied over
after each change, which would be inefficient. Look at the text
system documentation and see how to make changes to the text storage.
Douglas Davidson
OK, I did follow your advice, and tried
NSMutableAttributedString *astr = [oattributedTextView textStorage];
[astr replaceCharactersInRange:elementRange withString:[te c]];
where oattributedTextView is the outlet of the NSTextView.
Now, I got the change immediately shown in my NSTextView.
Thanks!
Ivan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden