• 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: NSTextFieldCell Subclass for Image+Text, any faster way?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTextFieldCell Subclass for Image+Text, any faster way?
      • From: Brian Amerige <email@hidden>
References: 
 >NSTextFieldCell Subclass for Image+Text, any faster way? (From: Brian Amerige <email@hidden>)
 >Re: NSTextFieldCell Subclass for Image+Text, any faster way? (From: Scott Stevenson <email@hidden>)
 >Re: NSTextFieldCell Subclass for Image+Text, any faster way? (From: Brian Amerige <email@hidden>)

  • Prev by Date: "-(BOOL)copyPath:(NSString *)source toPath:(NSString *)destination handler:(id)handler" doesnt work properly when file copied across network.
  • Next by Date: Re: "-(BOOL)copyPath:(NSString *)source toPath:(NSString *)destination handler:(id)handler" doesnt work properly when file copied across network.
  • Previous by thread: Re: NSTextFieldCell Subclass for Image+Text, any faster way?
  • Next by thread: Re: NSTextFieldCell Subclass for Image+Text, any faster way?
  • Index(es):
    • Date
    • Thread