On 2010 Apr 19, at 08:56, Marco Masser wrote:

> I'm trying to implement a logging facility for an app ..., i.e. an 
> NSTableView with varying row heights.

> I found three different approaches to calculating the height for a given 
> width, but they all seem to be very performance-hungry:
> 1) (my favorite) I set the message string on my message column's 
> NSTextFieldCell directly and call -cellSizeForBounds:
> 2) Creating an NSAttributedString with the attributes of my cell, calculating 
> its size and then using the string's total width and my column's width.
> 3) Using some code from the docs involving an NSTextStorage, NSLayoutManager, 
> and an NSTextContainer.

I have written an app which has a log window with variable row heights, in the 
sense that some rows have one line of text, some have two and some have more.  
I have not noticed any drawing or resizing uglies.  I suppose I'm using what 
you call approach number 2.  It works by implementing the NSTableView delegate 
method -tableView:heightOfRow: in the table's array controller.

> calculate the number of rows (seems to be off some times).

This is a problem.  In my case, I don't need to calculate the height because my 
strings have a known number of hard line breaks.  However, assuming that the 
table's cell is an NSTextFieldCell, indeed you do have a problem.  Although you 
can get pretty close by changing the typesetter behavior in the layout manager 
you use to simulate the layout from the default NSTypesetterLatestBehavior to 
NSTypesetterBehavior_10_2_WithCompatibility, I've never found a way to measure 
the size of text rendered in an NSTextFieldCell with 100% reliability.

_______________________________________________

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