• 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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView


  • Subject: Re: NSTableView
  • From: David Blanton <email@hidden>
  • Date: Wed, 14 Jan 2009 12:23:11 -0700

Here is the code. Some notes,

	_browserView is an NSMatrix of NSImageCells
	Str is form a portable string library
	there are a few C++ classes used

Once a cell value is computed it is stored.

When moving a split view divider and covering the table that action is jerky. I thought storing the cell values would improve that but no.

Any and all comments please.

Oh, Shark said 16% objc-msgsend.

Thanks in advance!


/* numberOfRowsInTableView */ - (int)numberOfRowsInTableView:(NSTableView *)tableView { if(_browserView != nil) { int count = _browserView->fileList.GetCount(); [_browserView selectAll:self]; [_browserCells release]; _browserCells = [_browserView selectedCells]; [_browserCells retain]; return count; } else return 0; }

/* tableViewobjectValueForTableColumn:row */
- (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;
}

/* setupCell */
- (void)setupCell:(DTVCell*)cell forRow:(int)rowIndex column: (NSString*)colID {


BMatrixCell *xcell = [_browserCells objectAtIndex:rowIndex];
BEUtil beu;
if(xcell->_haveDesign == NO)
{
BEDesign design;
xcell->m_Design.SetFilename(xcell->mBFilename);
beu.GetFile(xcell->m_Design);
xcell->m_StitchCount = xcell->m_Design.StitchCount();
BEColorList becl;
xcell->m_Design.GetColorList(&becl);
xcell->m_ColorCount = becl.GetCount();
if(xcell->m_ColorCount>0) xcell->m_StitchCount -= (xcell- >m_ColorCount-1);
xcell->_haveDesign = YES;
}

if([colID compare:@"NAME"] == NSOrderedSame)
{
if(xcell->_name == nil)
{
Str s((const STRCHAR*)xcell->mBFilename.StripExtension());
xcell->_name = [NSString stringWithCString:(const char *)s encoding:NSASCIIStringEncoding];
[xcell->_name retain];
}
cell->_value = xcell->_name;
return;
}

if([colID compare:@"EXTENSION"] == NSOrderedSame)
{
if(xcell->_extension == nil)
{
Str s((const STRCHAR*)xcell->mBFilename.GetExtension());
xcell->_extension = [NSString stringWithCString:(const char *)s encoding:NSASCIIStringEncoding];
[xcell->_extension retain];
}
cell->_value = xcell->_extension;
return;
}

if([colID compare:@"COLORS"] == NSOrderedSame)
{
if(xcell->_colors == nil)
{
xcell->_colors = [NSString stringWithFormat:@"%d",xcell- >m_ColorCount];
[xcell->_colors retain];
}
cell->_value = xcell->_colors;
return;
}

if([colID compare:@"STITCHES"] == NSOrderedSame)
{
if(xcell->_stitches == nil)
{
xcell->_stitches = [NSString stringWithFormat:@"%d",xcell- >m_StitchCount];
[xcell->_stitches retain];
}
cell->_value = xcell->_stitches;
return;
}


if([colID compare:@"JUMPS"] == NSOrderedSame)
{
if(xcell->m_jumps == 0)
{
BEObj *obj;
POSITION pos = xcell->m_Design.GetHeadPosition();
while(pos)
{
obj = &xcell->m_Design.GetNext(pos);
obj->SetStitchCounts();
int jmp;
obj->m_data.GetData("CIMJUMPS",jmp);
xcell->m_jumps += jmp;
}
xcell->_jumps = [NSString stringWithFormat:@"%d",xcell->m_jumps];
[xcell->_jumps retain];

}
cell->_value = xcell->_jumps;
return;
}

if([colID compare:@"SIZE"] == NSOrderedSame)
{
if(xcell->_size == nil)
{
Str measure((const STRCHAR *)beu.GetMeasureString(1,xcell- >m_Design));
NSString *nsMeasure = [NSString stringWithCString:(const STRCHAR*) measure encoding:NSASCIIStringEncoding];
NSRange range = [nsMeasure rangeOfString:@":"];
NSString *sz = [nsMeasure substringToIndex:range.location];
range = [sz rangeOfString:@"mm"];
NSString *w = [sz substringToIndex:range.location];
NSString *h = [sz substringFromIndex:range.location + 2];
sz = [w stringByAppendingString:h];
xcell->_size = [sz substringToIndex:[sz length]-3];
[xcell->_size retain];
}
cell->_value = xcell->_size;
return;
}


if([colID compare:@"DATE"] == NSOrderedSame)
{

if(xcell->_date == nil)
{
Str dir((const STRCHAR*)xcell->mBFilename.GetDirectory());
Str file((const STRCHAR*)xcell->mBFilename.GetFileName());
NSString *nsdir = [NSString stringWithCString:(const char *)dir encoding:NSASCIIStringEncoding];
NSString *nsfile = [NSString stringWithCString:(const char *)file encoding:NSASCIIStringEncoding];
nsdir = [nsdir stringByAppendingPathComponent:nsfile];
NSDictionary *dict = [_fileManager fileAttributesAtPath:nsdir traverseLink:YES];
NSDate *date = [dict objectForKey:NSFileModificationDate];
xcell->_date = [date description];
xcell->_date = [xcell->_date substringToIndex:20];
[xcell->_date retain];
}
cell->_value = xcell->_date;
}
}





On Jan 14, 2009, at 11:30 AM, Andy Lee wrote:

On Jan 14, 2009, at 1:06 PM, Andy Lee wrote:
I forget if you said whether you're using bindings or a data source. If you're using a data source, how about posting your code for numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:? The docs for these two methods say they need to be very efficient.

I found your earlier post. It sounds like you already know tableView:objectValueForTableColumn:row: is slow. *Why* is it slow? Is it making some kind of network or database call? If your table only has 30 rows or so, why not cache the objects in an NSArray? Again, posting code might help.


--Andy




David Blanton





_______________________________________________

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


  • Follow-Ups:
    • Re: NSTableView
      • From: Corbin Dunn <email@hidden>
References: 
 >NSTableView (From: David Blanton <email@hidden>)
 >Re: NSTableView (From: Andy Lee <email@hidden>)
 >Re: NSTableView (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Debugging objc_msg errors
  • Next by Date: auto garbage collection race condition?
  • Previous by thread: Re: NSTableView
  • Next by thread: Re: NSTableView
  • Index(es):
    • Date
    • Thread