Re: NSTableView
Re: NSTableView
- Subject: Re: NSTableView
- From: Andy Lee <email@hidden>
- Date: Wed, 14 Jan 2009 14:46:21 -0500
On Jan 14, 2009, at 2:01 PM, David Blanton wrote:
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:
(NSTableColumn *)aTableColumn row:(int)rowIndex {
DTVCell* cell = [aTableColumn dataCell];
NSString* colID = [aTableColumn identifier];
[self setupCell:cell forRow:rowIndex column:colID];
return cell;
}
Typically this method does not return a cell -- it returns a simple
object like an NSString or NSNumber. I glanced (only very quickly) at
your Shark profile and noticed a lot of calls to -[NSCell
copyWithZone:], which I'm *guessing* is because the cell you're
returning from this method is getting copied unnecessarily. If you
returned a string, it would get copied too, but that would probably be
a lot cheaper than copying a cell.
- (void)setupCell:(DTVCell*)cell forRow:(int)rowIndex column:
(NSString*)colID {
I haven't looked closely at the code for this method, but it seems to
be doing a lot of work. I don't know if that work involves loading
large files or hitting a network connection, but I assume *you* do.
If it's doing something you ALREADY KNOW is expensive, you shouldn't
be calling it every time tableView:objectValueForTableColumn:row: is
called. Again, I refer to the doc for
tableView:objectValueForTableColumn:row:
Note: tableView:objectValueForTableColumn:row: is called each time
the table cell needs to be redisplayed, so it must be efficient.
(Technically, "being efficient" is not the same as "running in a very
short amount of time," but that's obviously what they meant.)
A common pattern for a table view's data source is for it to have an
array of objects that you want to display, one object for each row of
the table. numberOfRowsInTableView: returns the size of the array.
For a single-column table, tableView:objectValueForTableColumn:row:
returns the nth element of the array. For a multi-column table, it
gets the nth element and asks it for the value to display in the
specified column. I suspect you will get better results if you take
this approach.
If you *don't* know why tableView:objectValueForTableColumn:row: is
slow (if you expect it to be almost instantaneous), then you're back
to analyzing the Shark profile, and your problem has nothing to do
with your table view per se.
As a side note, you shouldn't use direct ivar access as in "cell-
>_value = xcell->_date". This violates not only encapsulation but
memory management rules.
--Andy
_______________________________________________
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