NSTextView and setString
NSTextView and setString
- Subject: NSTextView and setString
- From: Brock Brandenberg <email@hidden>
- Date: Thu, 21 Mar 2002 12:21:02 -0600
Hi.
Has anyone had any problems using setString in an NSTextView that
already contains an attributed string?
I am using a subclass of NSTextView that I am declaring and
instantiating at runtime, not from a nib file. I am doing this so that I
can have a fully editable text view with font glyphs that I can overlay
graphic controls onto. You can think of it as a simple desktop
publishing app where the text frame objects are my custom NSTextView
subclass. Any comments about the inappropriateness of this are
welcome :) It may be better for me to build a compound object with a
factory NSTextView (or something else) at a lower layer, then pass
events down to it as appropriate.
All is well and fine creating and adding it as a subview to a custom
NSView. In initWithFrame, I am stuffing a default string into the
NSTextView, then creating a dictionary of attributes including font and
color information and applying them to the textStorage object over the
range of characters in the string (for now, I am not yet setting
typingAttributes for the NSTextView). Later, I am changing the contents
of the NSTextView subclass with setString with the contents of a
NSDictionary passed in from a notification.
The problem is that the setString is failing with an exception if the
new string is shorter than the old string, to the effect of "Exception
raised during posting of notification. Ignored. exception: ***
NSRunStorage, _NSBlockNumberForIndex(): index (4) beyond array bounds
(4)". In this particular case, the old string was 6 chars long and the
new one is 4. It appears that something is trying to apply attributes to
the new string over the range of the old one, hence the out of bounds
error. BTW, if I set the string to @"" first, then set it to the new
string, all is fine.
Any ideas?
Brock Brandenberg
----- industrial design @ bergdesign ------
web site: www.bergdesign.com
email: email@hidden
--------------------------------------------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.