Attributed strings, Texviews, Bindings and programmatic changes

Discussion in 'Mac Programming' started by dryjoy, Mar 12, 2012.

  1. dryjoy macrumors regular

    Mar 19, 2009
    I have a very standard application with an array of my own model objects, controlled by an instance of NSArrayController and with various properties of the model bound to various view objects.

    That's all working well on a basic level, but among the views are some NSTextViews which are bound to NSMutableAttributedStrings, and what I would like to do is programmatically add or change attributes for the attributed strings and have these reflected in the textviews.

    I've tried all sorts of ways of doing this but to no avail. The textviews are set to allow richtext.

    My latest attempt has been something along the lines of:

    [anAttributedString setAttributes:headingsFont range:theRange]; //headings font is a suitable NSDictionary with the appropriate key and NSFont
    [[aTextView textStorage] setAttributedString:anAttributedString];
    Which doesn't work (no error but no change in formatting is visible in the textview).

    Is there a way I can do this? Or would I be better off forgetting mixing bindings and making changes programmatically for the textviews and dealing with them entirely programmatically? If I did this, I don't see why I couldn't still use bindings for the other view objects.

    This is my first serious coding query since I started getting into it all - please be gentle with me! Any help is greatly appreciated.

Share This Page