Re: NSTextView and setString
Re: NSTextView and setString
- Subject: Re: NSTextView and setString
- From: Douglas Davidson <email@hidden>
- Date: Thu, 21 Mar 2002 11:03:46 -0800
On Thursday, March 21, 2002, at 10:21 AM, Brock Brandenberg wrote:
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.
It's hard to tell what's happening here without more details--e.g., what
notification is this being called from? what is the backtrace at the
point when the exception is raised?--but I do have a suggestion: if you
are going to be modifying things at the text storage level, it is
probably cleaner and simpler to make all of your changes at that level
rather than doing some things via the view with setString:. It might
even clear up your problem, too. Remember to bracket multiple text
storage changes with beginEditing/endEditing.
Douglas Davidson
_______________________________________________
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.