NSTableView and Ellipses--Again
NSTableView and Ellipses--Again
- Subject: NSTableView and Ellipses--Again
- From: Buzz Andersen <email@hidden>
- Date: Sat, 10 Aug 2002 19:46:21 -0600
All,
Since I got no responses on my last post about this, I thought I'd post
again--this time with a slightly different question...
As I said in my last message, I am trying to implement the functionality
found in iTunes' table view that causes it to truncate strings which are too
long to fit within in a column and place ellipses (...) at the end of the
visible part.
Below is the code I'm using, which I am not very fond of. Essentially, I
iterate through each character in the string, add the current character to
the end of an NSMutableAttributedString, and use the size method in that
class to determine if the attributed string has reached a length yet that
would be too long for the column. If it has, I add the ellipses in the
proper place.
I know that this is an ugly way to do it, and it seems to contribute to
noticeable sluggishness as the user moves through the table view (the code
is called over and over by the "willDisplayCell" delegate method).
Does anyone have any ideas about a better way to do it? I know it must be
possible to create *something* more efficient, because iTunes' table view
doesn't seem to suffer the kind of sluggishness I'm seeing...
Any advice anyone could offer would be most appreciated!
Thanks,
Buzz
--- BEGIN CODE ---
if (stringSize.width > columnWidth) {
result = [[NSMutableAttributedString alloc] init];
for (i = 0; i < [attString length]; i++) {
[result appendAttributedString: [attString
attributedSubstringFromRange: NSMakeRange(i, 1)]];
if ([result size].width > columnWidth) {
[result replaceCharactersInRange: NSMakeRange(i - 2, [result
length] - (i - 2)) withString: @"..."];
break;
}
}
[result autorelease];
return [result string];
}
else {
return [attString string];
}
--- END CODE ---
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.