Re: NSTextView and setString
Re: NSTextView and setString
- Subject: Re: NSTextView and setString
- From: Brock Brandenberg <email@hidden>
- Date: Thu, 21 Mar 2002 14:59:26 -0600
HI Douglas.
I had not considered the bracketing because almost everything that I do
is at the higher level except for the initial attribute setting. As a
result, I pulled out the textStorage setAttributes: and used
setTypingAttributes: on the NSTextView instead, but the result is no
better.
But, bracketing the calls may be necessary at a different level. I am
using a textContainer with bounds of 10,000,000 in both dimensions so
that the layoutManager doesn't wrap the type (with the appropriate
setHeightTracksTextView: etc.). I'm then getting the bounding rects for
the glyphs with layoutManager boundingRectForGlyphRange: and adjusting
the bounds rect and frame rect accordingly. If I simply no-op the layout
manager call to boundingRectForGlyphRange:, the setString works fine, so
the problem may lie with something the layoutManager is doing. There is
almost no documentation on the application of these layoutManager APIs,
so it may be possible that the "glyph generation" that the minimal docs
does mention needs to be bracketed with some set-up and tear-down calls.
I wish that I could figure out what notification the exception happens
on, but I don't know how to trap it. My knowledge of Cocoa is just too
limited at this point.
Thanks for the suggestion.
Brock Brandenberg
On Thursday, March 21, 2002, at 01:03 PM, Douglas Davidson wrote:
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
----- 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.