Skip navigation.
 
mlRe: NSMutableAttributedString binding
FROM : Ivan C Myrvold
DATE : Thu Jan 10 20:28:14 2008

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

Related mailsAuthorDate
mlNSMutableAttributedString binding Ivan C Myrvold Jan 10, 18:11
mlRe: NSMutableAttributedString binding Douglas Davidson Jan 10, 18:28
mlRe: NSMutableAttributedString binding Jonathan Dann Jan 10, 19:23
mlRe: NSMutableAttributedString binding Ivan C Myrvold Jan 10, 20:28
mlRe: NSMutableAttributedString binding Douglas Davidson Jan 10, 20:32