• 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: Brian Amerige <email@hidden>
  • Date: Tue, 21 Nov 2006 15:58:44 -0500

Thanks all!

I took all of both Stephane and Scott's advice, it's now performing beautifully.

In the method where I add the objects to the remoteFiles array in the first place, I determine the Icons associated with each row, and store them into their own separate array. (I considered adding the Images under another key in the remoteFiles array, but considering the amount of usage remoteFiles has (and in the majority of cases, the Image would be useless and ignored in these cases), I would lose performance in other areas.

So, in my method (which is called only once to determine the icons for each row), I do:
----
[remoteIconFiles removeAllObjects];
NSImage *Icon;
if ([[file objectForKey:@"NSFileType"] isEqualToString:@"NSFileTypeRegular"])
{
Icon = [[NSWorkspace sharedWorkspace] iconForFileType:[[file objectForKey:@"cxFilenameKey"] pathExtension]];
}
else
{
Icon = folderIcon;
}
[Icon setSize:NSMakeSize(16,16)];
[remoteIconFiles addObject:Icon];


------
And in the willDisplayCell method, I do:

		if ([aCell isImageAndTextCell])
		{
			[aCell setImage:[remoteIconFiles objectAtIndex:rowIndex]];
		}

Thanks so much,
Brian.

On Nov 21, 2006, at 6:04 AM, Stephane Sudre wrote:


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];


_______________________________________________

Cocoa-dev mailing list      (email@hidden)

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: 
 >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>)
 >Re: NSTextFieldCell Subclass for Image+Text, any faster way? (From: Stephane Sudre <email@hidden>)

  • Prev by Date: Re: NSTableView and NSView
  • Next by Date: Re: Custom images with NSProgressIndicator
  • Previous by thread: Re: NSTextFieldCell Subclass for Image+Text, any faster way?
  • Next by thread: Custom images with NSProgressIndicator
  • Index(es):
    • Date
    • Thread