Re: NSTableColumn : Help required
Re: NSTableColumn : Help required
- Subject: Re: NSTableColumn : Help required
- From: Fritz Anderson <email@hidden>
- Date: Wed, 20 Nov 2002 15:50:58 -0600
This involves more steps than can be jotted down in detail into a
single email, but here are the considerations...
I assume you have the full-length string readily available. You give
the example of a currency amount, but I'm going to assume you can get
that from your data source, or by way of an NSNumberFormatter.
I also assume that the character that didn't come through in your
message was the horizontal-ellipsis character (...).
In your implementation of tableView:objectValueForTableColumn:row:, for
the column in question, you can pass -width to the column to get its
width. You then define this method:
@interface NSString (truncation)
- (NSString *) truncatedWithEllipsisAtEnd: (float) width;
@end
Its logic is:
Obtain the string-drawing attributes for the cell and put them in an
NSDictionary.
If [self sizeWithAttributes: attributeDictionary].width <= width
return [[self retain] autorelease];
Otherwise, set up a binary search:
lowBound, highBound, middle observe integer math.
lowBound = 1, highBound = [self length] -1
let Subst(n) be equivalent to
[[self substringToIndex: n] stringByAppendingString:
horizontalEllipsis]
Verify that Subst(lowBound) is narrower than width (exception, or maybe
return horizontal ellipsis, if not)
and that Subst(highBound) is wider than width (return Subst(highBound)
if not)
while lowBound < highBound - 1
middle = (lowBound + highBound) / 2
if Subst(middle) narrower than width
lowBound = middle
else if Subst(middle) is wider than width
highBound = middle
else
return Subst(middle)
return Subst(lowBound)
Or: You could look at the OmniFoundation framework, which I remember
has ellipsis-truncation (both end and middle) methods, though I swear I
didn't lift them here. (For one thing, I'm pretty sure my notation for
Subst() is killingly inefficient, or could be made less so with a local
autorelease pool.)
-- F
On Sunday, November 17, 2002, at 07:56 AM, Rakesh Pandey wrote:
Hi All,
I have a table to display a report. I don't want to make the columns
of this
table Autoresizable, rather I want to show a '
' as the last character when
a cell has to show a string longer than its width. When the column is
resized the display value should appear properly.
For example : See the cell has to show $20000 and its width is
sufficinet
enough to show just $200 the I want to display $20
no inform the users to
resize the column to see the entire text. If the user resizez the
column
and still it can't show the entire string the '
' should appear.
If any one has already done it, please help me out.
Thanks in advance
Rakesh
_______________________________________________
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.
_______________________________________________
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.