• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableview - tableView:heightOfRow: not behaving
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableview - tableView:heightOfRow: not behaving


  • Subject: Re: NSTableview - tableView:heightOfRow: not behaving
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 5 Jul 2009 23:00:39 -0700

On Jul 5, 2009, at 17:06, Alex Holland wrote:

- (CGFloat)tableView:(NSTableView *)tv heightOfRow:(NSInteger)row
{
// Get second column (index 1 - status text)
// (first column, index 0, is Twitter profile pic)
NSTableColumn *column = [[tv tableColumns] objectAtIndex:1];
// Get text cell from second column for row
NSCell *cell = [column dataCellForRow:row];
// Calculate height using cellSizeForBounds, limiting it to width of column.
// Adding 10 pixels for padding.
float height = [cell cellSizeForBounds:
NSMakeRect(0.0, 0.0, [column width], 1000.0)].height+10.0;
// Profile pics are 48x48, so ensure size is at least 58px to allow some padding
height = MAX(height,58.0);
return height;
}

You're assuming that the cell has the current text, but it doesn't. (It would be far too inefficient to set the cell to the row's data before every call to tableView:heightOfRow:. It only gets set to the correct data for the row just before being drawn.)


Instead, you should find the text directly from your data model (using 'row'), measure it in some way that doesn't mess with the table view's internals (i.e. modifying its data cell is probably not a good idea, although I don't really know), and return the height from the that measurement. Note that this is likely to be kind of slow, in general, relative to the frequency with which this delegate method is called, so in a real app you'd probably consider caching the computed heights somehow.

The other thing wrong here (speaking from memory -- I haven't checked the documentation on this recently) is that it's generally a no-no to hard code column indexes. However, if you're getting the text from your data model anyway, you won't need the column at all.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSTableview - tableView:heightOfRow: not behaving (From: Alex Holland <email@hidden>)

  • Prev by Date: Re: Switching Contents of NSView
  • Next by Date: How to share Cocoa classes?
  • Previous by thread: NSTableview - tableView:heightOfRow: not behaving
  • Next by thread: Re: NSTableview - tableView:heightOfRow: not behaving
  • Index(es):
    • Date
    • Thread