Your question has caused me to dig deeper...

It seems that when I handle both the NSViewFrameDidChangeNotification and the 
NSTableViewSelectionDidChangeNotification notifications, the attributedString 
of the textView's layout manager is nil.

This is very interesting...  Here's a bit more of my setup.  I have an 
NSTableView, populated by an NSArrayController.  The textView's data is bound 
to the arrayController's selection.data (which provides an RTF NSData object).  
That works as expected.  I observe the ViewFrameDidChangeNotification on the 
textView, so that as the user types in text and the textview grows, I can also 
resize the superview accordingly.

I was listening to the selectionDidChange notification of the NSTableView, 
because (I've observed) when the data to be shown in the textview is smaller 
than the current size of the textview, it does not resize down to fit the 
content.  This is the behavior that I'm looking for.

However, in both of these methods, the attributedString of the textview is nil, 
thus giving me the strange results I'm seeing.

What would be the appropriate way to get the behavior I'm looking for?

Thanks,

Dave

On Nov 19, 2009, at 4:28 PM, Jens Alfke wrote:

> 
> On Nov 19, 2009, at 2:39 PM, Dave DeLong wrote:
> 
>> When I print out the size or rect that these return, I invariably get either 
>> {0, 0} or something absurd like {{1.17076e-318, 2.29357e-314}, 
>> {2.30359e-314, 2.1224e-314}} (that's just running the rect through 
>> NSStringFromRect())
> 
> Make sure the receiver (the NSAttributedString) isn't nil. The Obj-C runtime 
> gives undefined results for a struct-based method return value if the 
> receiver is nil; so you'll end up with garbage like this. (This is because it 
> doesn't know at runtime how large the struct is, so it can't safely fill it 
> in with zeroes.)
> 
> Put in something like NSAssert(str!=nil, @"str is nil"); before the call.
> 
> —Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to