Re: NSTextFieldCell Subclass for Image+Text, any faster way?
Re: NSTextFieldCell Subclass for Image+Text, any faster way?
- Subject: Re: NSTextFieldCell Subclass for Image+Text, any faster way?
- From: Stephane Sudre <email@hidden>
- Date: Tue, 21 Nov 2006 12:04:58 +0100
On 21 nov. 06, at 05:59, Brian Amerige wrote:
Hi all,
I tried out the attributed string, and the performance was the same,
and considering others have said the performance should be fine with
the subclass, I'm going to use a subclass as it does a lot of the
dirty work forme. Here's my code:
if ([[aCell className] isEqualToString:@"ImageAndTextCell"])
{
if ([[[remoteFiles objectAtIndex:rowIndex]
objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeDirectory"])
{
IconForRemoteTableRow = [[NSWorkspace sharedWorkspace]
iconForFile:@"/tmp"];
}
else
{
IconForRemoteTableRow = [[NSWorkspace sharedWorkspace]
iconForFileType:[[[remoteFiles objectAtIndex:rowIndex]
objectForKey:@"cxFilenameKey"] pathExtension]];
}
[IconForRemoteTableRow setSize:NSMakeSize(16,16)];
[aCell setImage:IconForRemoteTableRow];
}
Additionally to Scott's notes:
- pre-optimize your code when dealing with NSTableView. While it's
considered stupid by some people, I always found it was the best thing
to do when dealing with NSTableView because tableData source methods
are called very often...
- use constants instead of file paths when possible
NSDictionary * tFileInfoDictionary;
tFileInfoDictionary=[remoteFiles objectAtIndex:rowIndex];
if ([[tFileInfoDictionary objectForKey:@"NSFileType"]
isEqualToString:@"NSFileTypeDirectory"])
{
static NSImage * sFolderIcon=nil;
if (sFolderIcon ==nil)
{
sFolderIcon=[[[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)] retain];
stFolderIcon setSize:NSMakeSize(16,16)];
}
IconForRemoteTableRow= sFolderIcon;
}
else
{
[...] // Cache algorithm suggested by Scott
}
[aCell setImage:IconForRemoteTableRow];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden